MATLAB Answers

Returning minimum row index of an array

8 views (last 30 days)
mlam on 7 Sep 2015
Commented: mohamed essabir on 23 Feb 2020
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 Comment
Varun Pai
Varun Pai on 7 Sep 2015
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).

Sign in to comment.

Answers (1)

rihab on 7 Sep 2015
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.


Community Treasure Hunt

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

Start Hunting!