3D Figures of Looping Variables

3 ビュー (過去 30 日間)
Zaharaddeen Hussaini
Zaharaddeen Hussaini 2018 年 9 月 10 日
コメント済み: ADragon 2018 年 9 月 10 日
Hi,
I am tryig to make a 3D plot of some variables all in a loop. The best way I can describe it by citing an example.
For example:
clc;
clear;
close all;
count = 1;
for A = 1:5
for B = 3:8
for C = 2:7
Sum= A+B+C;
Product = A*B*C;
val(1) = A;
val(2) = B;
val(3) = C;
val(4) = Sum;
val(5) = Product;
Save (count,:) = val;
count = count+1;
end
end
end
Now , I want to have three different figures for Variables A, B & C. Each figure has on the X axis a variable (Say C in the first case), Sum on the Y axis and Products on the Z- Axis with only C varying while A & B points are kept fixed.
2nd Figure would have B varying as A & C are fixed. The last would have A Varying with B & C fixed.
Any help/guide on how to this quickly and effectively please?

採用された回答

ADragon
ADragon 2018 年 9 月 10 日
Hi Zaharaddeen, you can use a for loop to plot each variable.
Vars = {'A','B','C'};
for i = 1:3
figure
plot3(Save(:,i),Save(:,4),Save(:,5))
xlabel(Vars{i})
ylabel('Sum')
zlabel('Product')
grid on
end
AD
  2 件のコメント
Zaharaddeen Hussaini
Zaharaddeen Hussaini 2018 年 9 月 10 日
So best way to do it is to make the plot after the loops are done. Kept trying to do it whilst inside the loop.
Thanks a lot. You made it look very easy.
ADragon
ADragon 2018 年 9 月 10 日
No problem! Yes, I would recommend plotting after you construct your matrix. If you do it inside the loop, Matlab will create an object handle for each point which I don't think is very efficient. AD

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by