Azzera filtri
Azzera filtri

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

6 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Jan
Jan il 24 Ott 2022
Modificato: Jan il 24 Ott 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.

Più risposte (0)

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by