How can I change a matrix name in workspace during my script ?
7 views (last 30 days)
I am new here and i'm trying to rename matrix (6x7 size) called matrixuplink and matrixdownlink in the workspace with a specific name which comes from inputs.
The only way i found to do this is to defined manually the name in my script and tells that this value is equal to my matrix. I wanted to know if is it possible to do this by giving the name from inputs ?
My matrix final name is defined with two inputs : name and chX.
Thank you in advance for yours answers.
Stephen23 on 22 Jul 2022
Edited: Stephen23 on 22 Jul 2022
The problem is caused by your data design, which forces meta-data into variable names. Forcing meta-data into variable names makes accessing data slow, complex, and fragile:
Your code would be simpler, more efficient, and more robust if you stored meta-data (which is data after all) in some variables rather than in the variable names. That is the recommended approach.
However, if you wish to continue with this slow, complex, fragile approach which will break when the user enters invalid characters, then you can do so by creating them as fields of a structure:
tmp = struct();
fnm = sprintf(..);
tmp.(fnm) = someArray;
and then saving that structure using the '-STRUCT' option (this stores the fields as individual arrays):
But note that your code would be simpler, more efficient, and much more robust if you simply stored all of that meta-data in some variables and used exactly the same variable names in all of your MAT files:
Note that you should always LOAD into an output variable:
S = load(..)