# Error in using eval statement

1 view (last 30 days)
Ramesh Bala on 10 Jan 2022
Edited: Stephen23 on 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 ?
eval(['Energy_H_A',num2str(1),'S',num2str(1),' = rms(H_A',num2str(1),'S',num2str(1);]);
##### 2 CommentsShowHide 1 older comment
Ramesh Bala on 10 Jan 2022
Thank you Stephen for your valuable reply.Yes that's right using names was wrong as it was indeed slow.

Paul on 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);]
ans = 'Energy_H_A1S1 = rms(H_A1S1'
should be:
['Energy_H_A',num2str(1),'S',num2str(1),' = rms(H_A',num2str(1),'S',num2str(1),');']
ans = 'Energy_H_A1S1 = rms(H_A1S1);'
Stephen23 on 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:

Walter Roberson on 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!"
Ramesh Bala on 10 Jan 2022
Thank you Walter ,Indeed Eval was causing slowness when runnign the code.Thank you for the link