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

19 views (last 30 days)
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 Comments
Ryan Livingston
Ryan Livingston on 9 Apr 2014
Edited: Ryan Livingston on 9 Apr 2014
Could you please elaborate on "but it didn't work"? Were there errors? If so what were they? Is the answer unexpected?
Aaron
Aaron on 10 Apr 2014
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.

Sign in to comment.

Answers (1)

Titus Edelhofer
Titus Edelhofer on 9 Apr 2014
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 Comments
Aaron
Aaron on 10 Apr 2014
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.

Sign in to comment.

Categories

Find more on Event Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!