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 件のコメント

Jan
Jan 2022 年 3 月 11 日
編集済み: Jan 2022 年 3 月 11 日
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

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

 採用された回答

Théodore Keller
Théodore Keller 2022 年 3 月 11 日

0 投票

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by