Reverse 2D-lookup table in Simulink
    27 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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 comentarios
  VBBV
      
      
 el 13 de Abr. de 2025
				
      Movida: VBBV
      
      
 el 13 de Abr. de 2025
  
			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). 
Respuesta aceptada
  Bruce
 el 13 de Abr. de 2025
        1 comentario
  VBBV
      
      
 el 13 de Abr. de 2025
				
      Editada: VBBV
      
      
 el 13 de Abr. de 2025
  
			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
Más respuestas (1)
  VBBV
      
      
 el 12 de Abr. de 2025
        @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)))
Ver también
Categorías
				Más información sobre Lookup Tables en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!