How to save iterations

1 次查看(过去 30 天)
Birender
Birender 2013-4-4
for i=0.01:0.1:1
x=0:i:5; % create Vector of x 0 -> L
N=length(x); % Calculate number of psi values (X)
n=1:N; % Create Vector for n with length of N
Vx=zeros([1 N]); % Create Vector of V(x)
eval(['n(' num2str(i) '=n;']);
% Calculate Energy & Potential
[H,U,E] = CalcUandE(N,x,Vx,hbar,m);
eval(['Hdx' num2str(i) '=H;']);
eval(['Udx' num2str(i) '=U;']);
eval(['Edx' num2str(i) '=E;']);
% Find Analytic for E
[Ea] = AnalyticE(hbar,n,m,L);
eval(['Eadx' num2str(i) '=Ea;']);
Hi I am trying to run my above code and using it store the different values of n, Hdx, Udx, Edx however I am running into an error as my vector i for the loop has decimals. I am hoping some one can assist. Thanking you in advance :)

采纳的回答

Image Analyst
Image Analyst 2013-4-4
编辑:Image Analyst 2013-4-4
Use an index counter
counter = 1;
for step = 0.01 : 0.1 : 1
% Loop code
Hdx(counter) = % whatever.
counter = counter + 1;
end
Don't use i as a loop index - it's also the imaginary variable. That's why I used step as the name of the loop index. Once you use an index for Hdx you won't need to use eval. See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by