Hi, I have a function I run, and it gives four matrixes as outputs (which is why I can't make a X(n) variable, but maybe a X{n} could work but I don't have the matlab skills or brains to see it). Now, I want to run this function over and over again, and I want to make a function that does just that. What I'm struggling with is to get the outputs saved as different names. I have some different conditions that I run my function under, and depending on the condition I want a different name. Preferentially I want the function that runs the first function to take part of the variable output names as inputs. A MWE could look something like this:
function [A B] = FirstScript(x)%
A = magic(3)*x; B = magic(3)*2x;%end
.
function FunctionRunner(OutputTitle) %I don't want the function to have any predefined outputs.
FirstPart = 'FirstPartOfTheName'; SecondPart = 'SecondParOfTheName'; FirstPart2 = 'SomeOtherFirstPartOfTheName'; SecondPart2 = 'SomeOtherSecondParOfTheName';%there are more versions of the title parts that the title could be called, but I don't think that is needed for a MWE.
for i = 1:3 y = strcat([FirstPart OutputTitle SecondPart num2str(i)]) z = strcat([FirstPart OutputTitle SecondPart2 num2str(i)]) [TheString_Of_y TheString_Of_z] = FirstScript(1); end for i = 1:3 y = strcat([FirstPart2 OutputTitle SecondPart num2str(i)]) z = strcat([FirstPart2 OutputTitle SecondPart2 num2str(i)]) [TheString_Of_y TheString_Of_z] = FirstScript(2); end end
I know that this is a stupid way to work in MATLAB, and I'm open for other smart solutions that might not explicitly be like this. But has the concept of storing each run separate, as I want to be able to easily identify them, individually, later. The second issue is that I want the function that I run the second function with (FunctionRunner) to put the outputs to my workspace—without writing down a ton of names as outputs of this function instead. Thank you for any help. And I know I'm not always best at explaining my issues so please feel free to ask.
Best Answer