How to plot plot multiple vectors from a for loop ?

Hello everybody,
Here is my code, I am trying to plot, for each point of y variable (21 points) the corrsponding vector (each vector is made of the (0;0) coordinate point and the (y;z) coordinate).
Based on for loop structure I computed the (y;z) values for each y value, made a variable XY containing all the vectors that need to be plotted on the same figure. I struggle about the plotting, could you help me about this please ?
The idea is to have as final look a kind of a chinese fan you know :)
PFL = 25.4;
y = -20 : 2 : 20;
for i = 1 : length(y)
z(i) = sqrt((4 * PFL * y(i))) + (4 * PFL^2);
XY(i,:) = [y(i); z(i)]; % the formula for the vector coordinates (xb-xa; yb-ya) with a(0;0)
A = XY'; % swap rows and columns to use plotv()
for j = 1 : length(z)
plotv(A(:,j));
end
end
Thank you very much !

1 commentaire

Jan
Jan le 11 Mar 2022
Modifié(e) : Jan le 11 Mar 2022
Do you really mean plotv() from the deep leraning toolbox, or plot()?
The data have an imaginary part due to the square root of negative numbers. How do you want to display this?
plot() clears the axes before drawing. Avoid this by collecting the lines:
% Before the loop:
axes('NextPlot', 'add'); % Equivalent to: hold on

Connectez-vous pour commenter.

 Réponse acceptée

This solved my problem ! Many thanks !
axes('NextPlot', 'add');

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by