Matlab lookup table interpolation

24 ビュー (過去 30 日間)
Umz
Umz 2022 年 7 月 13 日
コメント済み: Umz 2022 年 7 月 15 日
Hello Everyone,
I have a set of tables as shown in the figure. This is the dummy data.
I would like to interpolate these tables at some inbetween value k2 under two circumstances:
  • When rows and columns coloured in brown have same steps.
  • When rows and columns coloured in brown may have some intermediate values for the table k2.
I was looking at the griddedInterpolant as the potential solution, but I don't know how to make interpolant with two matrices (coloured in green). Any leads would be highly appreciated.
Thanks
  1 件のコメント
dpb
dpb 2022 年 7 月 13 日
You've described interpolating between planes of a 3D array but not given any values for the "k" dimension not the value to which to interpolate. Given the first condition that the X/Y coordinates of the tables are consistent, it's simply linear interpolation across each cell location from 1 to 3 via the fractional value of 2. But, we dunno what those are.
Handling the second case simply means not interpolating a given row/column if the output array contains a value.
You could set up interp3 for this, but since the first two variables aren't being interpolated over, it's overkill; I think I'd just use arrayfun and interp1 as the guts of an anonymous function...or, given you can only use linear, probably just straight-ahead compute and apply the fraction to the entire array with logical addressing to handle the already-present locations. With that reflection, looks like it might be only a one-liner, or maybe two.

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

採用された回答

dpb
dpb 2022 年 7 月 13 日
OK, the first case with some assumptions...
commandhistory
M1=repmat([10:10:50].',1,3);
M2=repmat([35:10:75].',1,3);
K=[1:3].'; % arbitrary values for the interpolating direction
fnk=@(k)(k-K(1))/(K(3)-K(1)); % function compute fraction of input between planes
M=cat(3,M1,zeros(size(M1)),M2); % build the composite array (not mandatory, just chose to do)
fnI=@(k)M(:,:,1)+k*(M(:,:,3)-M(:,:,1)); % the interpolating function
% example usage
>> I=fnI(fnk(2)); % get the midpoint for example...
I =
22.5 22.5 22.5
32.5 32.5 32.5
42.5 42.5 42.5
52.5 52.5 52.5
62.5 62.5 62.5
>> M(:,:,2)=I; % fill in the array or whatever with result
All one would have to do for the second case is build a logical addressing vector for assignment if M(:,:,2) already contains values at some points and only assign where aren't values.
  3 件のコメント
dpb
dpb 2022 年 7 月 13 日
Sign wouldn't matter; it would just indicate the second value should be lower than the first...change the second array so third column is negative of original--
M2(:,3)=-M2(:,3);
fnI=@(k)M1+k*(M2-M1);
fnI(fnk(2))
ans =
22.5 22.5 -12.5
32.5 32.5 -12.5
42.5 42.5 -12.5
52.5 52.5 -12.5
62.5 62.5 -12.5
M=(cat(3,M1,M2));
mean(M,3)
ans =
22.5 22.5 -12.5
32.5 32.5 -12.5
42.5 42.5 -12.5
52.5 52.5 -12.5
62.5 62.5 -12.5
and you notice you still get same result at the middle as the mean as you should -- result will match regardless what value of k is between the two limits.
NB AND WHERE MAY HAVE GONE WRONG...
NB: You MUST redefine the anonymous function fnI after any changes to the values in the M array(s) -- anonymous functions store any variables in their definitions not in the argument list in the function definition itself -- so changing M w/o redefining the interpolating function will continue to return the same result as it did originally; it doesn't know anything about the updated M.
Should have noted this before, probably, a more generic way to write it would be to include the M values in the argument list and pass them to the function.
Umz
Umz 2022 年 7 月 15 日
I guess that what I might have missed, haven't tried this again but will check it. I suppose It should work. Thanks for the help.!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by