how to use eval function in order to get the value of variable with fieldname ?
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!