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

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

Why are you using eval() for this instead of run() ?
Usman Ahmad
Usman Ahmad 2019년 9월 6일
편집: Usman Ahmad 2019년 9월 6일
Hi Walter,
I am working on an already existing code and it has this eval function despite all the known issues of eval. I am just updating the code using these if conditions to update some parameter values.
No worries, I got it fixed now and it seems to work fine with eval. My initializations were messing up earlier.
Thanks anyway.
@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) ?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

태그

질문:

2019년 9월 6일

댓글:

2023년 9월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by