필터 지우기
필터 지우기

Interpolation of data that depends on two variables

조회 수: 13 (최근 30일)
Bas Siebers
Bas Siebers 2015년 5월 21일
댓글: Bas Siebers 2015년 5월 21일
Hi guys,
I have the following set of data:
sigma=[0;0;0;0;0;1;1;1;1;1;2;2;2;2;2];
alpha=[0;1;2;3;4;0;1;2;3;4;0;1;2;3;4];
C=[10;11;12;13;14;15;16;17;18;19;20;21;22;23;24];
Now I want to know wat the value of C is if my calculate alpha is 2.5 and sigma is 1.5.
To solve this problem, I have tried to use the function interp2. But I get an error.
Can somebody help me with this?
Thanks in advance, Bas Siebers

채택된 답변

Star Strider
Star Strider 2015년 5월 21일
Use the scatteredInterpolant function:
sigma=[0;0;0;0;0;1;1;1;1;1;2;2;2;2;2];
alpha=[0;1;2;3;4;0;1;2;3;4;0;1;2;3;4];
C=[10;11;12;13;14;15;16;17;18;19;20;21;22;23;24];
F = scatteredInterpolant(sigma, alpha, C);
Cnew = F(1.5, 2.5);
figure(1)
stem3(sigma, alpha, C)
hold on
stem3(2.5, 1.5, Cnew, 'r')
hold off
grid on
xlabel('\sigma')
ylabel('\alpha')
It plots ‘Cnew’, your interpolated value for ‘C’, in red.
  댓글 수: 2
Bas Siebers
Bas Siebers 2015년 5월 21일
Thanks, this exactly what i was looking for
Star Strider
Star Strider 2015년 5월 21일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

John D'Errico
John D'Errico 2015년 5월 21일
편집: John D'Errico 2015년 5월 21일
sigma=[0;0;0;0;0;1;1;1;1;1;2;2;2;2;2];
alpha=[0;1;2;3;4;0;1;2;3;4;0;1;2;3;4];
C=[10;11;12;13;14;15;16;17;18;19;20;21;22;23;24];
You have nicely gridded data already. Reshape will suffice to make it into a 2-d array. This is probably why you had an error, because you had the data strung out into vectors.
sigma = reshape(sigma,5,3);
alpha = reshape(alpha,5,3);
C = reshape(C,5,3);
So now we can plot C.
surf(sigma,alpha,C)
And interp2 will now work properly.
interp2(sigma,alpha,C,1.5,2.5)
ans =
20
It is important to understand that scatteredInterpolant is not needed, because your data is completely gridded already. That makes scatteredInterpolant less efficient than need be otherwise. As well, interp2 allows you to use a spline interpolant if you so desire, whereas scatterdInterpolant is limited to at most a linear interpolant. griddedInterpolant does allow the alternative (smoother) methods for interpolation.
In fact, interp2 looks to be something that MAY eventually be replaced by griddedInterpolant, at least they seem to be making hints along those lines in the help.

Andrei Bobrov
Andrei Bobrov 2015년 5월 21일
편집: Andrei Bobrov 2015년 5월 21일
[y,x] = ndgrid(unique(alpha),unique(sigma));
v = reshape(C,size(x));
f = griddedInterpolant(x,y,v);
example of using:
>>f(1.5,2.5)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by