Automatic function output numbering based on the sets of input arguments
6 次查看(过去 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?
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!