Find indices in 2D Matrix
35 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Bianka Markovic
il 29 Lug 2021
Modificato: the cyclist
il 30 Lug 2021
Hello everyone,
I'm trying to solve he problem with my indices. I have a 2D matrix A with ones and zeros. Now i want to define my other matrix B on those coordinates where A=1. But in the end i still want to have an 2D Matrix, not a vector with indeces.
Does anyone know how this could be solved.
Thank you!
A = rand(50,20)>.3;
B=rand(50,20);
newmatrix=B(A);
0 Commenti
Risposta accettata
the cyclist
il 29 Lug 2021
Is this what you mean? (I made the matrices smaller, just to show the result.)
A = rand(5,2)>.3;
B = rand(5,2);
newmatrix = zeros(size(A));
newmatrix(A) = B(A)
5 Commenti
the cyclist
il 30 Lug 2021
Modificato: the cyclist
il 30 Lug 2021
Ah, sorry. You must have an older version of MATLAB. Newer versions (since R2016b) have implicit expansion. Glad you found bsxfun.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!