Reverse 2D-lookup table in Simulink
I tried to implement a reverse 2D lookup table in Simulink according to the following description by Fangjun Jiang:
https://de.mathworks.com/matlabcentral/answers/12809-reverse-2d-lookup-table?s_tid=sug_su
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?I tried to implement a reverse 2D lookup table in Simulink according to the following description by Fangjun Jiang:
https://de.mathworks.com/matlabcentral/answers/12809-reverse-2d-lookup-table?s_tid=sug_su
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? I tried to implement a reverse 2D lookup table in Simulink according to the following description by Fangjun Jiang:
https://de.mathworks.com/matlabcentral/answers/12809-reverse-2d-lookup-table?s_tid=sug_su
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? lookup table, reverse, simulink MATLAB Answers — New Questions