How to implement interpolation using Prelookup using a MATLAB function?

22 ビュー (過去 30 日間)
Amr
Amr 2025 年 11 月 25 日 8:24
回答済み: Walter Roberson 2025 年 11 月 25 日 20:48
I have data with size 1201 26 37 384
I want to interpolate the first three dimenssions to get the fourth F(dim1, dim2, dim3) = column with size 348.
I'm using interpolation Using Prelookup and Prelookup to interpolate the first three dimentions and get the output is the fourth diminsion.
How can I implement this using matlab function instead of the simulink blocks?
I have tried using `griddedInterpolant` inside MATLAB funciton, but seems Simulink does not like it.
Is there any ideas?

回答 (2 件)

Chuguang Pan
Chuguang Pan 2025 年 11 月 25 日 9:15
@Amr. interpn can be used for N-D interpolation (table lookup).
Data = rand(1201,26,37,384);
[X1,X2,X3] = ndgrid(linspace(0,2,1201),linspace(0,2,26),linspace(0,2,37));
[X1q,X2q,X3q] = ndgrid(linspace(1,2,50));
Data_query=arrayfun(@(idx) interpn(X1,X2,X3,Data(:,:,:,idx),X1q,X2q,X3q,'linear'),1:384,"UniformOutput",false);
Data_output = cat(4,Data_query{:});
size(Data_output)
ans = 1×4
50 50 50 384
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  3 件のコメント
Walter Roberson
Walter Roberson 2025 年 11 月 25 日 10:28
I am confused about whether your target is implementation in Simulink (seems like it from your comments); or if your target is outside Simulink (as requested explicitly in your initial question) ?
Amr
Amr 2025 年 11 月 25 日 11:00
Sorry for confusion.
I wanted to implement it in a Matlab function inside Simulink.
when I said that How can I implement this using matlab function instead of the simulink blocks? I meant to use the matlab function inside simulink instead of using Simulink interpolation Using Prelookup and Prelookup blocks.
I hope I have clarified it.

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


Walter Roberson
Walter Roberson 2025 年 11 月 25 日 20:48
Convert your 4D data into a 3D array together with an (1201*26*37) x 384 array. The 3D array values should be column indices into the N x 384 array, and "nearest" interpolation should be done (in order to ensure that the outputs are indeed column indices.)
So, interpolated F(dim1, dim2, dim3) will return column indices into the N x 384 array, and you then use the returned column indices to extract the appropriate 384 values.

カテゴリ

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

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by