Returning minimum row index of an array

2 次查看(过去 30 天)
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 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by