Plot Different Line Styles using a for loop plot

조회 수: 7 (최근 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 CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by