MATLAB: I have variables ‘Ereal2’,E​real3,Erea​l4,Ereal5.​….so on…..how to call these variable in a single loop one by one.

MATLAB

These variables are vector in form

Best Answer

Hi Ravi
I have to agree with Jonas. But if you insist to use indexing which is embedded to the variable name, you can take some ideas from the following piece of code
clear; clc;
for n=1:10
% assign a value to each variable
strcmd=['Ereal' num2str(n) '=n^2 ;'];
eval(strcmd);
% display the value of each variable
disp(['Ereal' num2str(n) ' = ' num2str(eval(['Ereal' num2str(n)]))]);
end
The "key idea" is eval() function. You can find more info about this function on Mathworks help files