Plot Different Line Styles using a for loop plot

9 ビュー (過去 30 日間)
David Harra
David Harra 2023 年 2 月 8 日
編集済み: Sulaymon Eshkabilov 2023 年 2 月 8 日
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
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 件のコメント
David Harra
David Harra 2023 年 2 月 8 日
Thank You got everything working perfectly.
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 2 月 8 日
Most welcome! Glad to help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by