필터 지우기
필터 지우기

How to vectorize a matrix?

조회 수: 33 (최근 30일)
Sky Scrapper
Sky Scrapper 2019년 1월 8일
댓글: Sky Scrapper 2019년 1월 14일
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!
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2019년 1월 8일
Not clear. Don't understand the question.

댓글을 달려면 로그인하십시오.

채택된 답변

OCDER
OCDER 2019년 1월 8일
%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
Stephan
Stephan 2019년 1월 14일
편집: Stephan 2019년 1월 14일
A = 0:size(B,1)-1
Sky Scrapper
Sky Scrapper 2019년 1월 14일
oh i see. i tried: A= 0 : size ((B-1),1)).
I had little bit misunderstanding. thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by