How to fix this error?

조회 수: 2 (최근 30일)
Habib
Habib 2017년 5월 11일
답변: usha shree 2019년 8월 9일
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