Automatic function output numbering based on the sets of input arguments
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Karthik Nagaraj
le 12 Juil 2021
Modifié(e) : Karthik Nagaraj
le 13 Juil 2021
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 commentaires
Réponse acceptée
Walter Roberson
le 13 Juil 2021
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 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Entering Commands dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!