Reverse 2D-lookup Table
이전 댓글 표시
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
Image Analyst
2011년 8월 6일
Is your function single-valued? Does each Z value have one unique (X,Y) location? For example, Z=rand(1000,1000) would have lots of locations (perhaps a million or more) that could be interpolated to have a value of 0.5.
Owen
2011년 8월 7일
Pablo sanchez
2013년 7월 25일
Dear, I had the same doubt, excellent, thank you very much,very gratefull..
marouan akhabbil
2022년 3월 16일
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
2022년 9월 2일
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?
채택된 답변
추가 답변 (1개)
Fangjun Jiang
2011년 8월 8일
1 개 추천
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
Guohong
2011년 12월 6일
I've got the same issue however don't understand your words...What do you mean 10 points for A and 9 points for C? Sorry for the stupid question, new to simulink.
Fangjun Jiang
2011년 12월 6일
The mention of 10 points or 9 points is just an example. Owen was trying to put the code in the answer into an Embedded MATLAB Function in a Simulink model. I was trying to say not to do that as the EMF is going to be executed at every time step. I expect this look-up table reversing only needs to be done once. Once you reverse the table and get the desired look-up table data, you can use the Simulink look-up table block to do the interpolation.
Guohong
2011년 12월 7일
I understand when you said trying to avoid EMF, however didn't understand how to build the matrix with A, C as inputs. I presume if A is a 10 points array and C is a 9 one, we'll need B1 a 10X9 matrix, right?
Fangjun Jiang
2011년 12월 7일
Yes, I usually try to make the number of rows and columns to be different so it's easier to identify column vs. row.
Guohong
2011년 12월 8일
ok, but could you explain a little more in detail about how to make this B1 matrix? Thanks a lot.
Fangjun Jiang
2011년 12월 8일
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
2011년 12월 8일
I think I got your idea. Just use lookup table dynamic to build another lookup table of Z and B, right?
카테고리
도움말 센터 및 File Exchange에서 Array and Matrix Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!