Returning minimum row index of an array

조회 수: 6 (최근 30일)
mlam
mlam 2015년 9월 7일
댓글: mohamed essabir 2020년 2월 23일
I understand that using the size function returns the max number of columns or rows in an array. How would you return the index for the first row or column? Is there a function that does that? For example:
A = [101 101 101;
153 153 153;
203 204 205;
55 255 255]
Using [row,column]=size(A) gives row = 4, column = 3 How would i return row = 1 or column = 1? Because i am trying to get the index for row 1 or column 1 to use in some if statements.
  댓글 수: 1
Varun Pai
Varun Pai 2015년 9월 7일
편집: Varun Pai 2015년 9월 7일
Dear friend,
Your question is little bit confusing. If you want to access the element at row = 1 and column =1, simply use A(1,1). Index of row=1 and column=1 is 1,1.
If you want to get the elements of first row only then you can use A(1,:), If you want to get the elements of first column only then you can use A(:,1).

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

답변 (1개)

rihab
rihab 2015년 9월 7일
If you want to know the row or column indices of any element in a matrix, use the 'find' function of matlab. For example,
[row,column]= find(a==204)
will return the row and column indices of element '204' in your matrix.

카테고리

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