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!