Returning minimum row index of an array

6 vues (au cours des 30 derniers jours)
mlam
mlam le 7 Sep 2015
Commenté : mohamed essabir le 23 Fév 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 commentaire
Varun Pai
Varun Pai le 7 Sep 2015
Modifié(e) : Varun Pai le 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).

Connectez-vous pour commenter.

Réponses (1)

rihab
rihab le 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.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by