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

6 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Jan
Jan am 24 Okt. 2022
Bearbeitet: Jan am 24 Okt. 2022
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.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by