why am i facing this error in plotting ?
4 views (last 30 days)
Show older comments
a=1;
CFL = 0.8;
tf = 4/3;% tmax = 4/3;
N=50;
x = linspace(-1,1,N);% i took x = [-5;5]
dx = 2 /(N-1);
dt = (CFL * dx)/ abs(a);
lambda = (dt/dx);
t = [-4/3 : tf];
%Initial conditions:
for i = 1: N
if abs(x(i)) < 1/3 %McS, wrong abs(x(i) < 1/3 )
u(i,1) = 1;
elseif abs(x(i)) > 1/3 & abs(x(i)) <= 1
u(i,1) = 0;
end
end
plot(x,u(:,1),'k')
the error is :
Error using *plot*
vectors must be the same length
Error in 'burger' (line20)
plot(x,u(:,1),'k')
0 Comments
Answers (1)
Star Strider
on 16 Dec 2017
Your code runs for me without error in R2017b.
One possibility is that since ‘x’ is a row vector and ‘u’ is a column vector, transposing ‘x’ to a column vector could solve your problem:
plot(x', u, 'k')
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!