How do I map array values on a logical array
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Riccardo Micci
le 12 Jan 2021
Commenté : Steve Eddins
le 12 Jan 2021
Hello,
I have a vector with numbers that i need to be remapped on different positions according to a logical bitmap array.
Example:
A = [3 6 8 1 0 -3];
B = [ 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0];
Result = [ 0 0 0 0 0 0 0 0 3 6 8 1 0 -3 0 0 0];
The number of ones in B always matches the length of A but in general length(B)~=length(A)
How can i do that without going through a for loop?
Thanks!
0 commentaires
Réponse acceptée
Steve Eddins
le 12 Jan 2021
C = zeros(size(B));
C(logical(B)) = A
Plus de réponses (1)
Bruno Luong
le 12 Jan 2021
Modifié(e) : Bruno Luong
le 12 Jan 2021
Result = zeros(size(B));
Result(B==1)=A
0 commentaires
Voir également
Catégories
En savoir plus sur Exponents and Logarithms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!