How can I make "eval" work with an if condition?

9 Ansichten (letzte 30 Tage)
Usman Ahmad
Usman Ahmad am 6 Sep. 2019
Kommentiert: Dyuman Joshi am 26 Sep. 2023
I have a text file containing initialization data for my simulations and there I have an if condition like this:
if (Data.m > 10 & Data.m < 100)
Data.limits = 2;
else
Data.limits = 1.0;
end
The data of the text file is saved in "temp" and when I execute "eval(temp)" it gives me the error as below.
"Dot indexing is not supported for variables of this type."
There are multiple variables in the text file like "User.a, User.b" or "Force.a. Force.b" and it works fine. Adding an "if condition" in the text file like above throws this error.
  4 Kommentare
Dyuman Joshi
Dyuman Joshi am 26 Sep. 2023
@Michael Doroginizky, any particular reason why you are suggesting to use eval() when there are better alternatively available (specially the approach given by @Steven Lord in the link you have posted) ?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Variables finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by