フィルターのクリア

Automatic function output numbering based on the sets of input arguments

1 回表示 (過去 30 日間)
Karthik Nagaraj
Karthik Nagaraj 2021 年 7 月 12 日
編集済み: Karthik Nagaraj 2021 年 7 月 13 日
I have created a function which has up to 10 inputs, which looks like this
[out1, out2, out3] =fun(A, B, C,D,E,F,G,H,I,J)
The function output is mainly dependent on A and B and the rest inputs are not always varying.
After each time I call the 'fun' with the one set of A and B, the outputs- out1_AB, out2_AB, out3_AB have to be stored separately. The outputs of the function are as expected.
For example for one set of A and B.
Assuming A=20; B=50;
[out1_A20B50, out2_ A20B50, out3_ A20B50] =fun(20, 50, C,D,E,F,G,H,I,J)
Save(‘out1_A20B50.mat’, ‘out1_A20B50’)
Save(‘out2_A20B50.mat’, ‘out1_A20B50’)
Save(‘out3_A20B50.mat’, ‘out1_A20B50’)
2nd set Assuming A=30; B=60;
[out1_A30B60, out2_ A30B60, out3_ A30B60] =fun(30, 60, C,D,E,F,G,H,I,J)
Save(‘out1_ A30B60.mat’, ‘out1_ A30B60’)
Save(‘out2_ A30B60.mat’, ‘out1_ A30B60’)
Save(‘out3_ A30B60.mat’, ‘out1_ A30B60’)
Similarly for 100 sets of A and B is there any simpler way to and get the 3 outputs each time with unique name for the output variables and save those outputs with corresponding unique filename.mat?

採用された回答

Walter Roberson
Walter Roberson 2021 年 7 月 13 日
out = cell(1,3);
[out{1:3}] = fun(A, B, C,D,E,F,G,H,I,J);
f = "out" + (1:3).' + "_A" + A + "B" + B;
for K = 1 : 3;
clear s
s.(f{K}) = out{K};
save(f{K}, '-struct', 's');
end
  1 件のコメント
Karthik Nagaraj
Karthik Nagaraj 2021 年 7 月 13 日
編集済み: Karthik Nagaraj 2021 年 7 月 13 日
Great! Thank you.
It works fine as intended.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by