Plot Different Line Styles using a for loop plot

9 Ansichten (letzte 30 Tage)
I am Trying to creat a plot that has 4 different curves and each curve has a different line style. I have tried a number of ways and can't get it to work. Perhaps it is the way I have set up my for loop. If I keep all line styles the same, the plot works fine.. My code is attached.
%% Now plot the log normal distribution when the volumetic mean is a constant
L=0:100;
L_bar = 25;
sigma_d = 0.25; %[0.25, 0.5, 0.75, 1.0]; % How the distribution changes with different standard deviations.
mu = log(L_bar) - 0.5*sigma_d^2;
L_tilda = exp(mu);
LineTypes={'-' '--' ':' '-.'};
P = zeros(1,length(L));
for sigma_d = [0.25, 0.5, 0.75, 1]
P= 1./(L.*sqrt(2*pi)*sigma_d).*exp(-log(L/L_tilda).^2/(2*sigma_d^2)) ;
hold on
plot(L,P,'LineWidth',2,'LineStyle',LineTypes{sigma_d})
xline(L_tilda, 'LineWidth', 2)
xlabel('L (\mu m)')
xticks([0 20 40 60 80 100])
ylabel('P(L)');
title('Log Normal Distribution LBAR=25')
set(gca, 'FontSize',10);
end
hold off
legend('\sigma_d =0.25', '\sigma_d= 0.5', '\sigma_d =0.75', '\sigma_d = 1')

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 8 Feb. 2023
Here is how you can get this plot:
clf; close all
L=0:100;
L_bar = 25;
sigma_d = 0.25; %[0.25, 0.5, 0.75, 1.0]; % How the distribution changes with different standard deviations.
mu = log(L_bar) - 0.5*sigma_d^2;
L_tilda = exp(mu);
LineTypes={'-' '--' ':' '-.'};
P = zeros(1,length(L));
sigma_d = [0.25, 0.5, 0.75, 1];
for ii=1:numel(sigma_d)
P= 1./(L.*sqrt(2*pi)*sigma_d(ii)).*exp(-log(L/L_tilda).^2/(2*sigma_d(ii)^2)) ;
plot(L,P,'LineWidth',2,'LineStyle',LineTypes{ii})
hold on
end
xline(L_tilda, 'LineWidth', 2)
xlabel('L (\mu m)')
xticks([0 20 40 60 80 100])
ylabel('P(L)');
title('Log Normal Distribution LBAR=25')
set(gca, 'FontSize',10);
hold off
legend('\sigma_d =0.25', '\sigma_d= 0.5', '\sigma_d =0.75', '\sigma_d = 1')
  4 Kommentare
David Harra
David Harra am 8 Feb. 2023
Thank You got everything working perfectly.
Sulaymon Eshkabilov
Sulaymon Eshkabilov am 8 Feb. 2023
Most welcome! Glad to help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by