Plotting from function per for-loop iteration

1 回表示 (過去 30 日間)
Dominic Hernandez
Dominic Hernandez 2022 年 6 月 26 日
コメント済み: Matt J 2022 年 6 月 27 日
I need to produce calculations and plots for a series of parameters. I have read that producing a new plot per for-loop iteration is not advised, but that is what I need. For example, I have the following function and code:
Function:
function test_function(input_test)
x = input_test.x;
y = input_test.y;
x+y
figure(1)
scatter(x,y)
figure(2)
scatter(x+y,y)
end
Code:
a = [1,2,3];
b = [1,2,4];
for i=1:3
for j = 1:3
input_test.x=a(i)
input_test.y=b(j)
test_function(input_test)
end
end
I want to call the function and output the calculation and plots for each iteration of the for-loop (ie: 9 calculations of x+y & 18 different plots). Right now this code can produce the 9 calculations of x+y but I am only getting the 2 plots of the last iteration at the bottom of the output window.
Any suggestions or other methods on how to produce a series of individual calculations and plots?

採用された回答

Matt J
Matt J 2022 年 6 月 26 日
編集済み: Matt J 2022 年 6 月 26 日
If you want new figure windows for each plot, don't specify a number for them:
figure
scatter(x,y)
figure
scatter(x+y,y)
  2 件のコメント
Dominic Hernandez
Dominic Hernandez 2022 年 6 月 27 日
Thank you! This works for the example code I posted here. My main code is still running but hopefully it works too.
Matt J
Matt J 2022 年 6 月 27 日
You're welcome. If it does work though, please click Accept.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by