Plot Different Line Styles using a for loop plot
8 次查看(过去 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')
0 个评论
采纳的回答
Sulaymon Eshkabilov
2023-2-8
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 Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!