Reverse 2D-lookup table in Simulink
Ältere Kommentare anzeigen
I tried to implement a reverse 2D lookup table in Simulink according to the following description by Fangjun Jiang:
First, I wrote the following Matlab code for testing and it does exactly what I expect:
% Absolute eccentricity range
e = 0:1e-06:1.5e-05;
% Piston phase angle range
rad = 0:2*pi/400:2*pi;
% Load capacity matrix
load('Tragkraft_alpha_AK_kpl_V03.mat');
load_cap = Tragkraft_alpha_AK_kpl_V03;
% Instant piston phase angle
rad_dyn = 3.12588469032184;
% Reverse 2D lookup table for load capacity
lookup = interp2(e,rad,load_cap,e,rad_dyn);
% Instant load capacity
load_dyn = 659.331131439451;
% Instant absolute eccentricity
e_dyn = interp1(lookup,e,load_dyn);
After that, I tried to implement it in Simulink using a MATLAB function block with the following code:
function e_dyn = fcn(rad_dyn, load_dyn, load_cap)
% absolute eccentricity range
e = 0:1e-06:1.5e-05;
% piston phase angle range
rad = 0:2*pi/400:2*pi;
% 2D lookup table for load capacity
lookup = interp2(e,rad,load_cap,e,rad_dyn);
% instant absolute eccentricity
e_dyn=interp1(lookup,e,load_dyn);
However, this leads to the following error message that I don't really understand. In my understanding the Simulink model should do exactly the same as the Matlab code. Can anybody tell me how to fix that in Simulink?

3 Kommentare
VBBV
am 12 Apr. 2025
rad_dyn = rad_dyn*ones(1,length(e))
That difference is probably due to Simulink block functionality which puts constraints on input data as opposed to Matlab coder. Moreover you can also use mixed array sizes for interp2 function as you want (scalar) for the purpose of reverse look up table . You can browse through the doc page of interp2 function output argument section for interpolated values (Vq).
Akzeptierte Antwort
Weitere Antworten (1)
@Bruce Xq, Yq must be vectors , in your one is scalar and other is vector.
e = 0:1e-6:1.5e-05
rad_dyn = 3.12588469032184
% piston phase angle range
rad = 0:2*pi/400:2*pi
% piston phase angle range rad = 0:2*pi/400:2*pi;
load_cap = rand(401,16)
lookup = interp2(e,rad,load_cap,e,rad_dyn*ones(1,length(e)))
1 Kommentar
Bruce
am 12 Apr. 2025
Kategorien
Mehr zu Lookup Tables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!