Simulink 3D matrix interpolation using pre-lookups
7 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
Paul
2024-6-26
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 个评论
Paul
2024-6-26
编辑:Paul
2024-7-1
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)
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
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)
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 Exchange 中查找有关 Linear Algebra 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!