フィルターのクリア

how to use eval function in order to get the value of variable with fieldname ?

11 ビュー (過去 30 日間)
Maia2022
Maia2022 2022 年 10 月 24 日
編集済み: Jan 2022 年 10 月 24 日
Hi,
I have a cell array with structure expression. I'd like to use eval function to populate a variable like this:
eval('Data{50}.Set{2} = [15.5 10.2; 0.01 2.0];');
in order to have:
Data{50}.Set{2} = [15.5 10.2; 0.01 2.0];
But I got this error:
Unable to perform assignment because dot indexing is not supported for variables of this type.
How can I handle this with eval ?
Thank you

採用された回答

Jan
Jan 2022 年 10 月 24 日
編集済み: Jan 2022 年 10 月 24 日
Why do you want to do this by the evil eval? See: TUTORIAL: how and why to avoid Eval . Beginners tend to try to solve problems by eval() not knowing, that this causes more problems than it solves.
But the error message has another reason: If Data is not a struct, you cannot append a field.
Data = 0;
Data.Set = 5
Unable to perform assignment because dot indexing is not supported for variables of this type.
The error is fuxed, if you define Data as a struct before. But the main question remains, why you want to do this by eval?
Data{50}.Set{2} = [15.5 10.2; 0.01 2.0];
This is perfect already.

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by