Borrar filtros
Borrar filtros

Matlab for loop plots curves in random order

1 visualización (últimos 30 días)
Arthur Moya
Arthur Moya el 23 de Abr. de 2021
Comentada: Star Strider el 24 de Abr. de 2021
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)

Respuesta aceptada

Star Strider
Star Strider el 23 de Abr. de 2021
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 comentarios
Arthur Moya
Arthur Moya el 24 de Abr. de 2021
@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 el 24 de Abr. de 2021
No worries!
I first encountered MATLAB in 1993, and I have been involved in Answers on and off since 2012. It just takes practice!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by