Error using griddedInterpolant: The grid vectors are not strictly monotonic increasing. please help me!

5 ビュー (過去 30 日間)
Dear All,
I have 3 vectors (x1, x2 and R). I want to build surface plot 'R' depending on 'x1' and 'x2' [R(x,x2)] by using "griddedInterpolant" but i get error "The grid vectors are not strictly monotonic increasing". Below show my code.
x1=[1.5 0.8 1.25 1 0.75 0.625 1.375 0.5 1.125];
x2=[0.875 0.56 0.5 0.75 1 0.81 0.69 0.625 0.94];
R=[25 24 21 26 28 29 26.5 26.6 26.1];
F = griddedInterpolant({x1,x2},R);
xq=0.5:0.1:1.5;
yq=0.5:0.1:1;
vq=F({xq,yq});
surf(xq,yq,vq)
please help me how to fix this error and regrid my data.
Many thanks

採用された回答

Stephen23
Stephen23 2019 年 11 月 25 日
編集済み: Stephen23 2019 年 11 月 25 日
Your data are scattered, not gridded:
so you will need to use a scattered interpolant:
For example, using the scatteredInterpolant class (which can also perform extrapolation):
>> x1 = [1.5,0.8,1.25,1,0.75,0.625,1.375,0.5,1.125];
>> x2 = [0.875,0.56,0.5,0.75,1,0.81,0.69,0.625,0.94];
>> R = [25,24,21,26,28,29,26.5,26.6,26.1];
>> F = scatteredInterpolant(x1(:),x2(:),R(:),'linear','linear');
>> xq = 0.5:0.1:1.5;
>> yq = 0.5:0.1:1;
>> vq = F({xq,yq});
And visualizing (note that input data which are not on the interpolation grid may appear to have different values from the plotted interpolated data, this is to be expected):
>> [xqM,yqM] = ndgrid(xq,yq);
>> surf(xqM,yqM,vq)
>> hold on
>> scatter3(x1,x2,R,'filled')
  1 件のコメント
Dam Tung
Dam Tung 2019 年 11 月 25 日
Dear Mr Stephen Cobeldick,
Thank you so much for your answer and explaining. I got it.

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

その他の回答 (0 件)

カテゴリ

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