using a value to find index in a matrix?
Mostra commenti meno recenti
How would one find the location inside a matrix? In this case I am looking for x, assuming it exists.
Matrix_A = randi([1 100],100,100)
x = randi ([1,100], 1)
Risposta accettata
Più risposte (2)
David Hill
il 22 Ott 2020
[i,j]=ind2sub(size(Matrix_A),find(Matrix_A==x));
1 Commento
Walter Roberson
il 22 Ott 2020
You might as well just use
[i, j] = find(Matrix_A == x)
There is a role for using ind2sub(), but really not until you are working in more than 2 dimensions.
Walter Roberson
il 22 Ott 2020
Like I replied to your other question that was essentially the same, use
ismember(x, Matrix_A)
If you are trying to find where in the matrix it occurs, then use the second output of ismember().
This assumes that there is only one match. If there might be multiple matches then you might as well use
[row, column] = find(Matrix_A == x)
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!