Plot Different Line Styles using a for loop plot

7 次查看(过去 30 天)
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')

采纳的回答

Sulaymon Eshkabilov
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by