Reverse 2D-lookup Table

84 Ansichten (letzte 30 Tage)
Owen
Owen am 1 Aug. 2011
Kommentiert: Michael Goebel am 4 Okt. 2023
I am having a lot of difficulty implementing this typ of controller in simulink.
To put it simply have a 2d-Lookup table a basically want to reverse engineer it. The 2d-lookup table takes in two input A and B and interpolates the corresponding output C in a large 79x101 matrix. I wish to define the output variable C for a fixed input variable A and find the corresponding variable B.
_____________
A--->| |
|2d-Looukup |--->C
B--->|___________|
____________
C--->| Reverse |
| lookup |--->B
A--->|___________|
What I have been attempting is to focus on first is the input A. So lets say for example that I have the following matrix.
0.4 0.5 0.6 0.7 (B)
____________________
17.9|67 89 95 108
(A) 18.0|74 92 110 123
18.1|80 97 115 127
18.2|84 106 119 135
(C)
I have an input of 18.046 for the input A. Now matlab will interpolate between 18.0
and 18.1 to give me the following output.
0.4 0.5 0.6 0.7 (B)
___________________
(A)8.046|76 94 112 125
(C)
So with the matrix output as shown below I define my desired output variable, e.g. C = 105. I then pass this variable C into a lookup table and matlab will interpolate the corresponding input variable B.
0.4 0.5 0.6 0.7
  __________________
(C) 105--->|76 94 111 125| ---> 0.57 (B)
Could anyone help me in acheieving this problem as I have been stuck on it for quite some time now. Much appreciated
Owen
  5 Kommentare
marouan akhabbil
marouan akhabbil am 16 Mär. 2022
Hello
i had the same issue i wanted to inverse a 2D lookup table, i tried the formula in the previous comments but it gives NAN values so i creted my own formula, it's so simple based on one interpolation :
here is my script
clc
nbrC1 = 3 ; %nombre d'elelements desiré dans le vecteur C1
A=[1 2 ];
B=[1 2 ];
C=[2 3 ; 3 4 ];
%objectif passer de : entrée sont A et B à entrées A et C
%calcul de la matrice B1 et des deux lignes A1 et C1
%A1=A inchangé
%etape 1 : les elements de la ligne C1
minC=min(min(C));
maxC=max(max(C));
precision=(maxC-minC)/(nbrC1-1) ;
C1=minC:precision:maxC ;
nA= size(A) ;
nA= nA(2) ;
nC1= size(C1) ;
nC1= nC1(2) ;
% etape 2 les valeurs de B1 ( matrice )
B1=zeros(nA,nC1);
for i= 1:nA
tmpC=C(i,:);
for j = 1:nC1
B1(i,:)=interp1( tmpC,B,C1, 'spline', 'extrap');
end
end
% the result
%B1
%C1
%A1 = A
%Marouan AKHABBIL
Michael Goebel
Michael Goebel am 2 Sep. 2022
This script works well, but not for me: A has a size of 8, B has a size of 32.
I set nbrC1 = 8
But it doesnt woork for me: C1 has weird values
How can i fix this?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 7 Aug. 2011
For a given value of A1 and C1, you should be able to find the corresponding value B1. Do a two-loop iteration on different values of A and C, you should be able to reverse engineer the lookup table.
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);
  21 Kommentare
Srinivasan
Srinivasan am 18 Sep. 2023
Bearbeitet: Srinivasan am 18 Sep. 2023
@Michael Goebel Thank you so much. Good find. Helped me a lot...
Michael Goebel
Michael Goebel am 4 Okt. 2023
My pleasure! I'm happy this helped

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Fangjun Jiang
Fangjun Jiang am 8 Aug. 2011
To use non codegen supported functions, you need to declare eml.extrinsic('function_name'), but that is not what I am suggesting.
I recommend you creating a 2D lookup table data using the code above in MATLAB, making A and C as inputs, choosing 10 points for A and 9 points for C for example. You just need to do this once and then you can use a lookup table block in your Simulink model.
  7 Kommentare
Fangjun Jiang
Fangjun Jiang am 8 Dez. 2011
That is the code in the accepted answer. I've updated the answer to reflect a correction from the comments (due to the mix of row and column).
If that is not your use case, you may want to ask a separate question.
Guohong
Guohong am 8 Dez. 2011
I think I got your idea. Just use lookup table dynamic to build another lookup table of Z and B, right?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by