Plotting multiple vectors from a function

13 ビュー (過去 30 日間)
RACHNA DANDWANI
RACHNA DANDWANI 2018 年 6 月 6 日
コメント済み: RACHNA DANDWANI 2018 年 6 月 13 日
Hello everyone. I have a function which returns 'n' sets of 3 values 'Ax', 'Ay' and 'Az'. I want to plot all the 'n' sets for 'Ax', 'Ay' and 'Az' on the same axis. How can it be done?
  3 件のコメント
Stephen23
Stephen23 2018 年 6 月 6 日
"I have a function which returns 'n' sets of 3 values 'Ax', 'Ay' and 'Az'."
This is not clear. Do you have a function with three scalar outputs, and you call this function n times, or do you call the function once and it returns three outputs each with n values, or something else?
" I want to plot all the 'n' sets for 'Ax', 'Ay' and 'Az' on the same axis."
What kind of plot: as a line plot, a scatter plot, a bar plot, ... ? Do the Ax, Ay, and Az indicate dimensions to plot?
RACHNA DANDWANI
RACHNA DANDWANI 2018 年 6 月 12 日
Yes, I have a function with three scalar outputs and it is called n times. I want a line plot. Ax, Ay and Az are the values returned by the function.

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

採用された回答

Stephen23
Stephen23 2018 年 6 月 12 日
Simpler than the accepted answer is to use a loop:
for k = 1:N
[Ax,Ay,Az] = yourFunction(...);
plot3(Ax,Ay,Az)
hold on
end

その他の回答 (1 件)

Prajit T R
Prajit T R 2018 年 6 月 11 日
Hi Rachna
As Rik mentioned, you need to use plot3 when you have three variables 'x', 'y' and 'z'. I presume that you have many sets of three values like 'Ax','Ay','Az' as one set, 'Bx','By','Bz' as the second set and so on for 'n' sets.
Let us say the size of each is 1x10. Now you wish to plot each of these 'n' sets with the corresponding 3 values each time in the same plot. You can do that as follows:
plot3(Ax,Ay,Az);
hold on
plot3(Bx,By,Bz);
.
.
.
plot3(Zx,Zy,Zz);
This will give you the plots of all 'n' sets (here, n=26 for example) in the same graph.
Hope this helps.
Prajit
  3 件のコメント
Stephen23
Stephen23 2018 年 6 月 12 日
編集済み: Stephen23 2018 年 6 月 12 日
"but what if value of 'n' is very large? I can't go on using hold on so many times."
You are right, that would be a crazy way to write code. But you accepted this answer, which means that you are happy that it does exactly what you want. If you wanted to write simpler code though, you could use a loop, like my answer shows.
" How can I plot graphs such that horizontal axis is the same but vertical axis takes 3 different parameters?"
Standard MATLAB allows two y-axes: one of the left, one on the right. For multiple Y-axes you can find some submissions on MATLAB File Exchange:
RACHNA DANDWANI
RACHNA DANDWANI 2018 年 6 月 13 日
Thank you very much

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

カテゴリ

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