Automating variable creation for the output of a function
Mostrar comentarios más antiguos
I have created a function which has upto 10 inputs, which looks like this
varAB=samefn(A, B, randomnum, C,D,E,F,G,H,J,)
The function output is mainly dependent on A and B and the rest inputs are not always varying. But each time I call the 'samefn' with the same inputs, the ouput 'varAB' is different as randonnum is also a input. The outputs I get each time I call the function is as expected.
I have to call this function for almost 1000 times for the same inputs and even keeping same A and B. So I created a loop and saved this in a cell. Now, each cell can be acessed and is working fine.
But my requirement is I want to save the output as unique variable and save as a separate matfile, each time I call the function 'samefn' for example varAB1, varAB2,...varAB100 for one set of A and B. As I have almost 10 sets of A and B, I have almost 10000 variables!
Eventhough acessing data through cell is easy, I want it as a separate variable so If I load it in python I can access these unique variables. If it is in cell format, all the data will stored in some other format which is not useful for my code there.
I know that creating a separate variable is not ideal way and using 'eval' is not advised.
Please help in automating the name of these variables for set of a A and B.
Like for one set A=1000, B=10 I want to save the variable for 1000 iterations like var_A1000_B10_1 up to varA1000_B10_1000
another set A=500, B=20 I want to save the variable for 1000 iterations like var_A500_B20_1 up to varA500_B20_1000.
Thanks!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Workspace Variables and MAT Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!