What does this mean "Vectors must be the same lengths"? And who can I fix it?
Show older comments
I am not good on Matlab and I can not see what the wrong is. Could you help me please? And can not get the plot.
x=0:0.002:2;
y(1)=1;
x(1)=0;
dx=0.002;
for n=2:1001
y(n)=y(n-1)+dx*fe13(x(n-1),y(n-1));
x(n)=x(n-1)+dx;
end
disp(y);
plot(x,y,'g--')
Answers (1)
Azzi Abdelmalek
on 29 Sep 2013
Edited: Azzi Abdelmalek
on 29 Sep 2013
There is no error in your code, but you can improve it
dx=0.002;
x=0:dx:2;
y=zeros(1,numel(x)) %pre-allocate
y(1)=1;
for n=2:1001
y(n)=y(n-1)+dx*fe13(x(n-1),y(n-1));
end
disp(y);
plot(x,y,'g--')
%you can also check the number of element in x and y
numel(x)
numel(y)
1 Comment
Mastafa Zouid
on 29 Sep 2013
Categories
Find more on Neuroimaging in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!