Returning minimum row index of an array

2 visualizzazioni (ultimi 30 giorni)
mlam
mlam il 7 Set 2015
Commentato: mohamed essabir il 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 Commento
Varun Pai
Varun Pai il 7 Set 2015
Modificato: Varun Pai il 7 Set 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).

Accedi per commentare.

Risposte (1)

rihab
rihab il 7 Set 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.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by