Interpolation Between Two known data points

19 ビュー (過去 30 日間)
Cordelia David
Cordelia David 2020 年 5 月 13 日
コメント済み: dpb 2020 年 5 月 13 日
Hi everyone, I'm trying to do a complicated interpolation. I have two matrices and I'm trying to find the data points between these two.
One of my matrices is like this:
[80000 80000 80000 80000 80000 80000 ....
1.273 1.346 1.419 1.4926 1.5658 1.63897 ....]
and the second is like this:
[69000 69000 69000 69000 69000 69000 ....
5.022 5.367 5.712 6.058 6.4038 6.749 .....]
I'm trying to interpolate what the values of the second column would be given this data if the first column of data was all 75000, similar in structure to the other two. I want it to look like this:
[75000 75000 75000 75000 75000 75000...
___ ___ ___ ___ ____ ___ .....]
However anytime I try to use the interp1 function I get the error "Sample points must be unique and sorted in ascending order." because the first columns are not unique. I'm not sure how to go about this. Any suggestions are appreciated!

採用された回答

dpb
dpb 2020 年 5 月 13 日
You're not looking across the variations in your two variables--another illustration why it's better to not create multiple variables for related data but to put into an array or other data structure that can reference programmatically -- see what happens if you were to use
X=[A(1,:);B(1,:)];
Y=[A(2,:);B(2,:)];
XO=75000;
YO=Y(1,:)+(XO-X(1,:))./diff(X).*diff(Y);
yields
>> YO
YO =
2.98 3.17 3.37 3.57 3.76 3.96
>>
for a single interpolant there's not much need for interp1
OTOH, you could use interp1 either in an anonymous function using the desired X0 and column(s) over which to interpolate as it isn't vectorized to accept more than a single vector X,Y input.
  4 件のコメント
dpb
dpb 2020 年 5 月 13 日
編集済み: dpb 2020 年 5 月 13 日
Would have to see what the code and data look like...if it's as you described above, it will work...if you get the error about the dimensions aren't the same, then they aren't even if you think they are or should be...or you may have an orientation problem w/ trying to catenate in the wrong direction even if same size.
Use whos on the variable list you're trying to catenate to find out who's out of line.
dpb
dpb 2020 年 5 月 13 日
Nothing says you can't use interp1, it's just not much of a savings if table has only two elements. But, the route would look something like:
fnInterp=@(i,xo)interp1(X(:,i),Y(:,i),xo); % define the anonymous function with table
% Example to use...
>> fnInterp(1,XO)
ans =
2.98
% To do all columns...
>> arrayfun(fnInterp,1:size(X,2),repelem(XO,size(X,2)))
ans =
2.98 3.17 3.37 3.57 3.76 3.96
% Compare to the explicit results from above...
>> YO=Y(1,:)+(XO-X(1,:))./diff(X).*diff(Y)
YO =
2.98 3.17 3.37 3.57 3.76 3.96
>>

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by