How to fix this error?

1 次查看(过去 30 天)
Habib
Habib 2017-5-11
I tried to run below script but "The grid vectors do not define a grid of points that match the given values." error is appeared and it is related to
z1=interp2(T,x,Z,T1,x1);
So how I can fix it?
L=5;
c=1;
n=100;
dt=0.005;
tf=5;
h=L/n;
l=dt*c/h;
l2=l^2;
M=l2*(diag(ones(n,1),1)+diag(ones(n,1),-1));
x=linspace(0,L,n+1);
f=x.*sin(4*pi*x/L);
g=0*x;
t=0;
w=f;
z=(1-l2)*f+f/2*M+dt*g;
t=t+dt;
Z=[];
T=[];
while t<tf
u=2*(1-l2)*z+z*M-w;
z=u;
Z=[Z,z];
T=[T,t];
w=z;
t=t+dt;
end
T1=linspace(0,tf,100);
x1=linspace(0,L,100);
z1=interp2(T,x,Z,T1,x1);
surf(x1,T1,z1);
axis([0 L 0 tf -5 5]);
xlabel('position')
ylabel('time')
zlabel('temperetur')
  1 个评论
KSSV
KSSV 2017-5-11
Read the documentation of interp2....and then call the function.
z1=interp2(T,x,Z,T1,x1);
In the above sizes of T,x,Z should be same but they are no tin your case; so the error.

请先登录,再进行评论。

回答(2 个)

KL
KL 2017-5-11
编辑:KL 2017-5-11
Did you read interp2 documentation ?
In your code,
z1=interp2(T,x,Z,T1,x1);
T and x must be of the same size and similarly T1 und x1. Z must be a matrix containing length(x) rows and length(T) columns.
whos T x Z T1 x1
Name Size Bytes Class Attributes
T 1x1000 8000 double
T1 1x100 800 double
Z 1x101000 808000 double
x 1x101 808 double
x1 1x100 800 double
  2 个评论
Habib
Habib 2017-5-11
Thanks. Yes, that is right.
but how I can make them same size? I tried but I didn't understand how do it. Infact, I don't know how i can reduce the size of "Z" and "T" inside "while" loop. the size of "Z" is 1*101000.
KL
KL 2017-5-11
编辑:KL 2017-5-11
It's hard to understand how you create Z or the relationship between x,T and Z. If you explain that maybe we could help.

请先登录,再进行评论。


usha shree
usha shree 2019-8-9
one dimensional error with two elements

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by