Automatic function output numbering based on the sets of input arguments

조회 수: 2 (최근 30일)
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by