Clear Filters
Clear Filters

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

6 views (last 30 days)
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

Accepted Answer

Jan
Jan on 24 Oct 2022
Edited: Jan on 24 Oct 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.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!