How can i interpolat my data

Could anyone help me ,How can i interpolat my data Q1(37*1),Q2(38*1),depth(0:5:25)
I Created a new depthe D ,and when i use this code >>
X = interp1 (D, Q2, depth, 'linear');
y = interp1 (D, Q1, depth, 'linear');
showing this error
Error using griddedInterpolant The grid vectors do not define a grid of points that match the given values. Error in interp1 (line 183) F = griddedInterpolant(X,V,method); thank you ....

回答 (1 件)

Star Strider
Star Strider 2017 年 1 月 17 日

0 投票

Your ‘D’, ‘Q1’ and ‘Q2’ vectors have to be the same length. You have to decide how to equalize them.
It is probably easier to create ‘D’ as (37x1) and remove one point (probably Q2(end)) from ‘Q2’.
If ‘depth’ uses values outside the range of ‘D’, remember to specify a method (for example 'linear') and use the 'extrap' option.

4 件のコメント

b.m.n n
b.m.n n 2017 年 1 月 21 日
編集済み: Star Strider 2017 年 1 月 21 日
thank you (Star Strider ) I created a new code, to equalize them . but it show the same error
D=[1:38];D=D';
depth1=[1:2:38];
Q1-interp1=ones(length(depth1),length(Q1)) *NaN;
Q2_interp1=ones(length(depth1),length(Q2)) *NaN;
k= length(Q1);
for i=1:k
Q1_interp1(:,1)=interp1(D(~isnan(D (:,i)),i),...
Q1(~isnan(Q1(:,i)),i),depth1,'linear');
end
Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.
Error in interp1 (line 183)
F = griddedInterpolant(X,V,method);
i don't know, what i missing
Star Strider
Star Strider 2017 年 1 月 21 日
Please do not name your variable ‘interp1’. This is called ‘overshadowing’ and is to be absolutely avoided. Go back and read the documentation on the interp1 function to see how it works, then give this another go.
Your code doesn’t make sense. I have no idea what you want to do, so I’ll leave you alone with the documentation for a while. You have to figure this out yourself.
b.m.n n
b.m.n n 2017 年 1 月 21 日
Thanks for your advice
Star Strider
Star Strider 2017 年 1 月 21 日
My pleasure.

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

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

質問済み:

2017 年 1 月 17 日

コメント済み:

2017 年 1 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by