フィルターのクリア

Appropriate imput for dynamic structure field name

5 ビュー (過去 30 日間)
Jessica Angulo Capel
Jessica Angulo Capel 2020 年 4 月 22 日
コメント済み: Steven Lord 2020 年 4 月 22 日
Hello,
I am trying to create a dynamic field name to a structe with the dot notation. I.e. I have a for loop with a string variable that changes in each iteration, and I want to create a field with that string name in each of the iterations.
msd = struct;
for i = 1:NFiles %for each file
FileName = Track_file{i,1}.File(1);
msd.(FileName) = []; %mal
end
The variable FileName is a string, but it keeps giving me an error: Invalid field name: 'Z:\Documents\Data\Sec1 vesicles\Spots in tracks statistics.csv'.
I also tried with:
msd.(FileName{1}) = [];
but the error is the same.
Why is it an invalid field name? which class of variable should I use as an imput?
Thank you very much!!!

採用された回答

Rik
Rik 2020 年 4 月 22 日
Field names in matlab adhere to the same rules as variable names. They can't start with a digit and can only contain 0-9, a-z, A-Z, and underscores.
Since Z:\Documents\Data\Sec1 vesicles\Spots in tracks statistics.csv is not a valid variable name, it can't be a field name. You will have to store that file name in a different way.
  2 件のコメント
Jessica Angulo Capel
Jessica Angulo Capel 2020 年 4 月 22 日
Thank you very much!
I was so convinced it had to be a problem with the imput variable type that I didn't think of that. So simple!
Steven Lord
Steven Lord 2020 年 4 月 22 日
You could try converting that variable name to a valid identifier using matlab.lang.makeValidName. Alternately if you're using release R2019b or later you could make a table with a variable name that's not a valid MATLAB identifier.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by