why am i facing this error in plotting ?

조회 수: 7 (최근 30일)
guetty abboud
guetty abboud 2017년 12월 16일
답변: Star Strider 2017년 12월 16일
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')

답변 (1개)

Star Strider
Star Strider 2017년 12월 16일
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')

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by