Plot multiple curves on a graph (involving a for loop within another)

2 ビュー (過去 30 日間)
I have the code below:
I want to plot a jvals x vetor_momentoj curve. In this example, I would have 4 curves (it=4), each one varying according to the 3 points defined (n=3).
Can anybody help me, please?
P.S. this is just a test code, and the value 0.03 used to define jvals is hypotetical. In the real code this value depends on the index i. Also, the value that the variable vetor_momentoj is assuming is hypotetical as well.

採用された回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 5 月 16 日
Hi,
Here is a solution.
...
for ii=1:it
jvals(ii,:)=linspace(0,0.3,n);
for jj=1:n
curvature=jvals(ii,jj);
x0j=1;
vector(ii,jj)=jj;
plot(jvals(ii,:), vector(ii,:), '-o'), hold all
end
end
...
Note that the values of jvals and vector can be generated easily without using for .. end loop. For larger sets of data, the loops are very inefficient.
it=4; n=3;
jvals=repmat(linspace(0,0.3,n),it,1)
vectors=repmat(1:n, it, 1);
Good luck.
  1 件のコメント
Ana Carolina da Silva Pacheco
Ana Carolina da Silva Pacheco 2021 年 5 月 17 日
Thank you! But the plot had to be outside the for inner loop ;) now it worked

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by