登录论坛

查看完整版本 : matlab-错误:索引必须为正整数或逻辑-如何制作电影


poster
2019-12-14, 20:46
我有这个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 && ihere 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 另外,如何才能更有效地编写最后一个循环(包含情节)以及如何制作电影?编辑->已解决



回答:

当i和j = 1时,u(j,i-1)和u(j-1,i)未定义;请记住,MATLAB矩阵索引从1开始,而不是0。



更多&回答... (https://stackoverflow.com/questions/5459784)