Replace an element in a matrix if it's a member of an array with zero
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a matrix A and an array B, I want to find any element in A that exist in B and replace it with zero. Any idea? Thanks
0 Commenti
Risposta accettata
michio
il 14 Dic 2016
ismember function can do the job. As it's stated in the doc page, "Lia = ismember(A,B) returns an array containing logical 1 (true) where the data in A is found in B."
Please try the following do see what it does.
b = magic(4)
a = [1,2,3,4];
I = ismember(b,a)
b(I) = 0
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!