フィルターのクリア

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.
  1 件のコメント
Bas Siebers
Bas Siebers 2015 年 5 月 21 日
Thanks, this method works nicer

サインインしてコメントする。


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 Center および File ExchangeInterpolation についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by