フィルターのクリア

Simulink 3D matrix interpolation using pre-lookups

37 ビュー (過去 30 日間)
Alborz Sakhaei
Alborz Sakhaei 2024 年 6 月 25 日 14:49
編集済み: Paul 2024 年 7 月 1 日 21:48
I have a 3D (6x5x2) matrix. I'd like to interpolate between 'surfaces' along the 3d dimension. To better visualize the problem, one can think of it as a plate with 2 stacked pankaces (each a 6x5 matrix (surface)). I'd like to make a new 5x6 pancake by interpolating between the two stacekd pancakes (along the 3rd dimesion). This needs to be done in Simulink.
I started off by using Matrix Interpolation (MI) block but I realized it would perhaps be more efficient if I directly use pre-lookups + interpolation-using-pre-lookups. See the example below including the .slx file.
In the pre-lookups, for the first 2 dimensions (5x6 --> k1,f1 and k2,f2), I'm enforcing all breakpoints to grab the entire 'surface' and simply use the 3rd dimension (x2) to interpolate between the 'surfaces'. I'm getting port 2 dimension error which I'd appreciate some help to debug.
I've also tried using 'Number of sub-table selection dimensions' as shows in the second picture below and no success.
I wonder, there should be easier ways of acheiving this given that this is a rather simple operation (interpolation between surfaces)

採用された回答

Paul
Paul 2024 年 6 月 26 日 4:34
Hi Alborz,
It looks like you're switching between 6x5 and 5x6 in your post. Assumign that a) the table is 6 x 5 x 2 as in the picture, and assuming b) you've set the breakpoint in the pre-lookup block to 1:6 for the first dimension and 1:5 for the second dimension
Set the 'constant value' of the top most Constant block to:
repmat((1:6).',1,5)
Set the 'constant value' of the middle Constant block to
repmat(1:5,6,1)
The dimensions of the outputs of pre-lookups should be 6 x 5.
Check if that gives the correct result.
  2 件のコメント
Alborz Sakhaei
Alborz Sakhaei 2024 年 6 月 26 日 12:17
Thanks Paul. It worked. Could you elborate on why the outputs of pre-lookups should be 2D (6x5) instead of 1D (6x1 and 5x1)? The later seems more intuitive to me
Paul
Paul 2024 年 6 月 26 日 13:27
編集済み: Paul 2024 年 7 月 1 日 21:48
it appears that the Interpolation Using Prelookup block does not do 'ndgrid expansion' on the query points as is done for the base Matlab interpn function. For example, using interpn to get the mean of the two pages ...
Set up the table data, assume that the independent variables for T span x: 1:6, y: 1:5, z: 1:2
rng(100)
T = rand(6,5,2);
We can cal interpn like this to get the mean of the two pages (and show it give the expected result)
[X,Y,Z] = ndgrid(1:6,1:5,1.5);
interpn(T,X,Y,Z) - mean(T,3)
ans = 6x5
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
What we're doing in the Simulink model is basically forming X, Y, but using a scalar for Z. Interestingly enough, interpn doesn't expand the third scalar argument (though apparently Simulink does!)
try
interpn(T,X,Y,1.5) - mean(T,3)
catch ME
ME.message
end
ans = 'Query coordinates input arrays must have the same size.'
Interpn can also be called like this, which is what you tried in Simulink and didn't work
interpn(T,1:6,1:5,1.5) - mean(T,3)
ans = 6x5
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
I guess the Simulink block just doesn't work the same way as interpn, at least I couldn't figure out how to make it accept two vector intputs; it appears it only does scalar expansion (even though interpn does not if the first two query coordinates are 2D arrays). The doc page for the block could be much more clear on this topic, especically to contrast with the interpn function. Users may expect the former to be the analog of the latter.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by