Dear All,
I have a matrix of 90x12. I need to use 2D look up table for matlab simulink. There i will have to put the vector of input values. That means, Vector for input values x:
[0 1 2 3 4 .........89] and vector for input values 'y': [0 1 2 3 4 5 6 ..11]. How can I write a code that will take the values for x and y automatically with the desired length?
Thanks!

 Réponse acceptée

OCDER
OCDER le 8 Jan 2019

1 vote

%Starting input
M = reshape(1:90*12, 90, 12); %your 90x12 lookup matrix
X = [0 1 3 4 89]; %input X lookup
Y = [0 1 3 5 11]; %input Y lookup
%Matlab does NOT use 0-based index. So add 1.
X = X+1;
Y = Y+1;
%Use sub2ind to to convert (X,Y) to a linear index.
Idx = sub2ind(size(M), X, Y);
%Collect your value based on index X and Y
Value = M(Idx);
In short, the above can be simplified as:
M = reshape(1:90*12, 90, 12); %your 90x12 lookup matrix
X = [0 1 3 4 89]; %input X lookup
Y = [0 1 3 5 11]; %input Y lookup
Value = M(sub2ind(size(M), X+1, Y+1));

5 commentaires

Sky Scrapper
Sky Scrapper le 11 Jan 2019
X = [0 1 3 4 89];
i just need to write this unitil 89 which is not possible.
if I write, A= 1:89 then it gives
A=[1 2 3 4 5 6 7 ...............89]
But now I need to get,
A=[0 1 2 3 4 5 6 7 ..............88]
I think it's very simple, but can't do that.
Stephan
Stephan le 11 Jan 2019
Modifié(e) : Stephan le 11 Jan 2019
A = 0:88;
?
Sky Scrapper
Sky Scrapper le 14 Jan 2019
If I am writing: A= 0 : size (B,1) %B is my matrix of 89x8
now it's showing: 0,1 ,2 .......................89
But I need: 0,1,2 ............................88
How to do this?
Stephan
Stephan le 14 Jan 2019
Modifié(e) : Stephan le 14 Jan 2019
A = 0:size(B,1)-1
Sky Scrapper
Sky Scrapper le 14 Jan 2019
oh i see. i tried: A= 0 : size ((B-1),1)).
I had little bit misunderstanding. thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by