フィルターのクリア

Matlab for loop plots curves in random order

1 回表示 (過去 30 日間)
Arthur Moya
Arthur Moya 2021 年 4 月 23 日
コメント済み: Star Strider 2021 年 4 月 24 日
Hi everyone,
What I am doing with the code below is to plot a curve of res_p vs P_e for every value of def_err. However, this produces over 50 plots and I would like to plot specific indices within def_err, namely 10, 20, 30, 40 and 50.
I suspect that I may be indexing into the variable def_err incorrectly such that the output plots are in random order(see plots below). And the values of the phase error seem oddly small as well.
clear all;
% P_e=pi/8;
lambda= 1.94e-2; %Ang
res_p= linspace(0,1.5,50); %Ang^-1
def_err = (0.4:0.4:20);%Ang
idx=[10, 20, 30, 40, 50];
A=def_err(idx);
for j=1:length(A);
P_e(:,j)= pi*lambda.*def_err(:,j).*res_p.^2;
for i=1:length(res_p)
hold on
plot(res_p,P_e.*(180/pi));
end
legend ('4 A','8 A','12 A','16 A','20 A','Location','best','Fontsize',14);
end
ylabel('Phase error (degrees)','Fontsize',14)
xlabel('Spatial frequency (q) (Ang^{-1})', 'Fontsize',14)

採用された回答

Star Strider
Star Strider 2021 年 4 月 23 日
The code required a bit of tweaking.
Try this —
lambda= 1.94e-2; %Ang
res_p= linspace(0,1.5,50); %Ang^-1
def_err = (0.4:0.4:20);%Ang
idx=[10, 20, 30, 40, 50];
A=def_err(idx);
for j=1:length(A);
P_e(:,j)= pi*lambda.*def_err(:,j).*res_p.^2;
end
figure
hold on
for i=1:length(A)
plot(res_p,P_e(:,i).*(180/pi), 'DisplayName',sprintf('%2d A',A(i)));
end
legend ('Location','best','Fontsize',14);
ylabel('Phase error (degrees)','Fontsize',14)
xlabel('Spatial frequency (q) (Ang^{-1})', 'Fontsize',14)
hold off
.
  4 件のコメント
Arthur Moya
Arthur Moya 2021 年 4 月 24 日
@Star Strider,Thank you again.
I guess I have to keep doing this until I build enough experience-backed confidence.
Cheers,
Arthur Moya
Star Strider
Star Strider 2021 年 4 月 24 日
No worries!
I first encountered MATLAB in 1993, and I have been involved in Answers on and off since 2012. It just takes practice!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by