Matlab 错误:在赋值A(I)=B中,B和I中的元素数必须相同
当我运行下面的代码时,我得到一个错误。下面标记了与特定行对应的错误Matlab 错误:在赋值A(I)=B中,B和I中的元素数必须相同,matlab,Matlab,当我运行下面的代码时,我得到一个错误。下面标记了与特定行对应的错误 global l m l=2; m=4; n=1000000; dt=0.0001; x=zeros(n,1); y=zeros(n,1); c=zeros(n,1); t=zeros(n,1); x(1)=1; y(1)=3; c(1)=1; t(1)=0.0; for ii=1:1000000 t(ii+1)=t(ii)+dt; x(ii+1)=x(ii)+dt*y(ii); y(ii+1)=y(
global l m
l=2;
m=4;
n=1000000;
dt=0.0001;
x=zeros(n,1);
y=zeros(n,1);
c=zeros(n,1);
t=zeros(n,1);
x(1)=1;
y(1)=3;
c(1)=1;
t(1)=0.0;
for ii=1:1000000
t(ii+1)=t(ii)+dt;
x(ii+1)=x(ii)+dt*y(ii);
y(ii+1)=y(ii)+dt*c(ii+1);
c(ii+1)=c(ii)+dt*((1-(l/y))*c(ii) + m);
end
plot(t,x,'b');
%plot(t,y,'g');
%plot(t,c,'r');
%plot3(x,y,z);
%legend('x','y','z');
%hold on;
grid on;
%axis([0 10 0 10 0 10]);
%end
相应的错误是
Error in ==> at 18
c(ii+1)=c(ii)+dt*((1-(l/y))*c(ii) + m);
In an assignment A(I) = B, the number of elements in B and
I must be the same.
请帮忙。提前谢谢。您的
l/y
第18行应该是
l/y(ii)
我相信。
y
是一个向量,因此您试图将一个包含1000000个条目的向量函数添加到c
向量的单个条目中。您可能想添加一个条目