How can I change a matrix name in workspace during my script ?

3 ビュー (過去 30 日間)
N/A
N/A 2022 年 7 月 22 日
コメント済み: Stephen23 2022 年 7 月 22 日
Hello together,
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
Stephen23 2022 年 7 月 22 日
編集済み: Stephen23 2022 年 7 月 22 日
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):
save(filename,'-struct',tmp)
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:
save(filename,'someArray','chX','name')
Note that you should always LOAD into an output variable:
S = load(..)
  2 件のコメント
N/A
N/A 2022 年 7 月 22 日
Hello Stephen,
Thank you for your answer, works pretty well. I will take a look to the forcing meta-data into variable names method.
Stephen23
Stephen23 2022 年 7 月 22 日
"I will take a look to the forcing meta-data into variable names method."
Even better would be taking a look at not forcing meta-data into variable names.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by