Help with 'Matrix Interpolation' Block in Simulink

5 次查看(过去 30 天)
I’m trying to use the Matrix Interpolation block (https://www.mathworks.com/help/simulink/ref_extras/matrixinterpolation.html) in Simulink, and I’d appreciate any guidance on how to set it up for my use case.
I have three 4×4 matrices—A1, A2, and A3—which correspond to speeds of 0 m/s, 8 m/s, and 15 m/s, respectively. I would like to perform linear interpolation for all 16 elements of the matrix element-wise between these matrices based on a varying speed input, using breakpoints at 0, 8, and 15 m/s.
Could someone please advise how to configure the Matrix Interpolation block to achieve this interpolation?

回答(1 个)

Abhas
Abhas 2025-6-13
To interpolate your three 4×4 matrices A₁, A₂, A₃ over speeds 0, 8, 15 m/s using Simulink’s Matrix Interpolation block, follow these steps:
  • Concatenate matrices into "TableData(:,:,1:3)".
  • Use breakpoints [0 8 15], "InterpolateDimension = 1", Linear + Clip.
  • Use "Prelookup" to compute "k1/f1" from speed.
  • Connect "Prelookup" outputs to "Matrix Interpolation block" for element‑wise interpolation.
The sample code to reflect the above steps is:
%% Define breakpoints and dummy matrices
speeds = [0, 8, 15];
A1 = [0 1 2 3; 1 2 3 4; 2 3 4 5; 3 4 5 6];
A2 = [6 5 4 3; 5 4 3 2; 4 3 2 1; 3 2 1 0];
A3 = [1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4];
TableData = cat(3, A1, A2, A3); % => size 4×4×3
%% Create Simulink model
model = 'interpMatrixDemo';
new_system(model);
open_system(model);
% Add blocks
add_block('simulink/Sources/In1', [model '/Speed']);
add_block('simulink/Lookup Tables/Prelookup', [model '/Prelookup']);
add_block('simulink/Lookup Tables/Interpolation Using Prelookup', [model '/MatrixInterp']);
add_block('simulink/Sinks/Out1', [model '/Out']);
% Wire up
add_line(model,'Speed/1','Prelookup/1');
add_line(model,'Prelookup/1','MatrixInterp/1'); % k1 (index)
add_line(model,'Prelookup/2','MatrixInterp/2'); % f1 (frac)
add_line(model,'MatrixInterp/1','Out/1');
% Configure Prelookup
set_param([model '/Prelookup'], ...
'BreakpointsSpecification','Explicit values', ...
'BreakpointsValues','[0 8 15]', ...
'OutputSelection','Index and fraction', ...
'ExtrapMethod','Clip');
% Configure Matrix Interpolation
set_param([model '/MatrixInterp'], ...
'NumberOfTableDimensions','1', ...
'TableSpecification','Explicit values', ...
'TableSource','Dialog', ...
'TableValue',mat2str(TableData), ...
'InterpMethod','Linear', ...
'ExtrapMethod','Clip');
% Save model
save_system(model);
open_system(model);
You may refer to the below documentation links to know more about the same:
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by