Error in using eval statement
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ramesh Bala
am 10 Jan. 2022
Bearbeitet: Stephen23
am 10 Jan. 2022
Why it shows an incomplete statement ?
I'm trying to write this statement using eval as follows : Energy_H_A1S1 = rms (H_A1S1); but in eval it shows error ?
Thanks in advance.
eval(['Energy_H_A',num2str(1),'S',num2str(1),' = rms(H_A',num2str(1),'S',num2str(1);]);
2 Kommentare
Stephen23
am 10 Jan. 2022
Bearbeitet: Stephen23
am 10 Jan. 2022
"I'm trying to write this statement using eval as follows : Energy_H_A1S1 = ..."
And that is the start of your problems.
Forcing meta-data into variable names makes acessing your data complex, slow, inefficient, and buggy... as your question demonstrates. Meta-data is data. Data should be stored in variables, not in variable names.
Your poor data design forces you into writing bad code, which could be easily avoided by storing the meta-data correctly.
Akzeptierte Antwort
Paul
am 10 Jan. 2022
There's almost certainly a better way to organize the data and store the results, but if you must use eval:
['Energy_H_A',num2str(1),'S',num2str(1),' = rms(H_A',num2str(1),'S',num2str(1);]
should be:
['Energy_H_A',num2str(1),'S',num2str(1),' = rms(H_A',num2str(1),'S',num2str(1),');']
4 Kommentare
Paul
am 10 Jan. 2022
Stephen23
am 10 Jan. 2022
Bearbeitet: Stephen23
am 10 Jan. 2022
"Could you please also post an example of the mentioned better way instead of eval as it takes high running time for this varying A1..4..S1..4 data"
The MATLAB introductory tutorials also show how to use MATLAB effectively by using arrays and indexing:
Weitere Antworten (1)
Walter Roberson
am 10 Jan. 2022
Asking how to use eval without problems is like asking how to use a chainsaw without its chain guard. It would be irresponsible for us to answer in any way other than "Don't do that!"
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!