0
我有這個matlab代碼,它給了我在標題中的錯誤。matlab - 錯誤:索引必須是一個正整數或邏輯 - 如何使電影
% solution of the scalar wave 1d equation
time=1000;
steps=1000;
a=input('Please enter the value of the ratio cdt/dx :');
%preallocate matrix u
u=zeros(steps,time);
%fill matrix u
for i=1:time-1
for j=1:steps-1
if (i==1)
u(j,i)=1; EDITED-->>from u(j,i)=0 % initial condition
else EDIT -->> j==1 and i==1 becomes j==2,i==2
if (j==2 && i>=2 && i<=50) % 50 is the time step for the pulse
u(j,i)=50;
else
%solution of wave equation
u(j,i+1)=a*a*(u(j+1,i)-2*u(j,i)+u(j-1,i))+2*u(j,i)-u(j,i-1);-->here is the error
end
end
end
end
for k=1:steps EDIT--> if mod(i,100)==0
figure(i/100)
plot(u(:,i+1))
plot(u(k,1:100))
plot(u(k,1:200))
plot(u(k,1:300))
plot(u(k,1:400))
....
end
此外,我怎樣才能更有效地寫最後一個循環(與劇情),我怎樣才能創建一個電影? EDITED - >求解
喬治,您實際上不必編輯您的問題以表明它們已解決。這幾乎是綠色複選標記在接受答案時所指示的內容,這是確定對您的問題最有幫助的解決方案的最佳方法。 – gnovice 2011-03-30 15:30:23