Reversing a 2D lookup table using S-fuction in Simulink

I would like to do a inversed 2D table lookup which was indicated as follows:
_____________
A--->| |
|2d-Looukup |--->C
B--->|___________|
____________
C--->| Reverse |
| lookup |--->B
A--->|___________|
I got online an idea that works, for example:
A=[17.9 18.0 18.1 18.2]'; B=[0.4 0.5 0.6 0.7]; C=[67 89 95 108 74 92 110 123 80 97 115 127 84 106 119 135];
A1=18.046; %Z=interp2(A,B,C,A1,B); Z=interp2(A,B,C',A1,B); C1=105; B1=interp1(Z,B,C1);
My question is that how can I code this idea to a S-funtion that can be used in my Simulink Model where A1 and C1 would be inputs? My S-function is listed as follows but it didn't work - appreicate if anyone can help - thanks.
function V = TD(A1,C1) %#codegen A = [17.9; 18.0; 18.1; 18.2]; B = [0.4, 0.5, 0.6, 0.7]; C = [67, 89, 95, 108; 74, 92, 110, 123; 80, 97, 115, 127; 84, 106, 119, 135];
Z = interp2(A,B,C',A1,B); V = interp1 (Z, B, C1);

2 commentaires

Ryan Livingston
Ryan Livingston le 9 Avr 2014
Modifié(e) : Ryan Livingston le 9 Avr 2014
Could you please elaborate on "but it didn't work"? Were there errors? If so what were they? Is the answer unexpected?
Error said undefined variable - no results were generated...but those codes ran well in Matlab. Seems in S-function the interp1 and interp2 can be recognized.

Connectez-vous pour commenter.

Réponses (1)

Titus Edelhofer
Titus Edelhofer le 9 Avr 2014

0 votes

Hi,
inverting will be possible only if the strict monoticity is given. If this is the case, you will end up with a usual 2D-Lookup again. I would suggest to compute the values within MATLAB and use the 2D-Lookup block instead of an S-Function.
Titus

2 commentaires

Yes, it is possible to invert the data - I established a reversed 2-D lookup table by writing a simple m-file program function in matlab. Still wondering if any trick for using S-function to deliever the reversed lookup data.
how did you do it?

Connectez-vous pour commenter.

Question posée :

le 7 Avr 2014

Commenté :

le 19 Déc 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by