I want to plot 3 different curves in the same graph (one parameter changing).
if true
for M0=1.5:0.5:2.5
disp('Valori scelti di Mi')
Mi=0.4:0.05:0.7
[...]
yyaxis left
grid minor
plot(Mi,Dad,'-^','LineWidth', 2,'MarkerSize',8);
xlabel('Mi','FontSize',14)
ylabel('Resistenza addizionale','FontSize',14)
title('Resistenza addizionale presa Pitot subcritica','FontSize',16)
yyaxis right
plot(Mi,PhiD,'-*','LineWidth',2,'MarkerSize',8)
ylabel('Coeff. di Portata','FontSize',14)
hold on
(ignore the first line if true).
Wath I want is to get this graph with every blu and orange line with different style operating inside the for command.

 Akzeptierte Antwort

dbmn
dbmn am 13 Apr. 2017

1 Stimme

You where almost correct. Just 2 small corrections:
1) "hold on" You added this line at the end of the script - this wont help you. Think about hold on as only between the two lines hold on / hold off that function is active (even if you dont specify hold off) -> just add hold on earlier in your code
2) use plotyy instead of plot. This allows you to get plots with 2 y axes
3) try to use handles, f.ex. h1 = plot(...). This allows you to accees the plotted lines much easier later in your script

3 Kommentare

Davide Bassignana
Davide Bassignana am 13 Apr. 2017
What do you mean by insert hold on earlier in the code? I am trying to use a separate cycle for in order to change colours of the lines (I am thinking at a vector containing the sequence of colours to be used, I know matlab already does this but in this case it doesen't work probably because I used yyaxis...)
This should do what your picture does. I took the title and labels out of the loop.
if true
figure; % create handle to figure
hold on
title('Resistenza addizionale presa Pitot subcritica','FontSize',16)
grid minor
xlabel('Mi','FontSize',14)
yyaxis left
ylabel('Resistenza addizionale','FontSize',14)
yyaxis right
ylabel('Coeff. di Portata','FontSize',14)
% Foor Loop
for M0=1.5:0.5:2.5
disp('Valori scelti di Mi')
Mi=0.4:0.05:0.7
Dad = rand(size(Mi));
PhiD = rand(size(Mi));
% Plot left thingy
yyaxis left
plot(Mi,Dad,'-^','LineWidth', 2,'MarkerSize',8);
% Plot right things
yyaxis right
plot(Mi,PhiD,'-*','LineWidth',2,'MarkerSize',8)
end
end
If you want changing Line styles you could define a variable such as (before the for loop)
my_linestyle = {'-^','-*','-o'};
i = 0;
and access this in the loop as follows
i = i+1;
plot(Mi,Dad,'linestyle',my_linestyle{i},'LineWidth', 2,'MarkerSize',8);
ooops. Correction - i was to fast. Now it should work :) (tested)
plot(Mi,Dad,my_linestyle{i},'LineWidth', 2,'MarkerSize',8);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 13 Apr. 2017

Kommentiert:

am 13 Apr. 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by