Reverse 2D-lookup table in Simulink
16 次查看(过去 30 天)
显示 更早的评论
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 个评论
VBBV
2025-4-13
移动:VBBV
2025-4-13
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).
采纳的回答
Bruce
2025-4-13
1 个评论
VBBV
2025-4-13
编辑:VBBV
2025-4-13
Ok. The key thing (line) is invoking the matlab built in function inside the Simulink function block although it was not recommended by @Fangjun Jiang
coder.extrinsic('griddata')
The rest of changes are not significant. You can try the same with interp2
更多回答(1 个)
VBBV
2025-4-12
@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)))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lookup Tables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!