hi every one, i need to ask a question, thank you
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
mina massoud
il 30 Giu 2019
Commentato: mina massoud
il 1 Lug 2019
if i have a row vector like this A=[ 0 1 1 1 0 0 1 1 0 1 ]
and another vector B=[ 1 2 3 4 5 6 ]
and i need to put the element of B in order in A when the element is equal to 1
so if it can possibile i need to return a vector with the dimensions of B like this [ 0 1 2 3 0 0 4 5 0 6 ] , how can i do it if it's possibile to do it in matlab
thank you
0 Commenti
Risposta accettata
Image Analyst
il 30 Giu 2019
Try this:
A=[ 0 1 1 1 0 0 1 1 0 1 ]
B=[ 1 2 3 4 5 6 ]
out = A % Initialize
out(logical(A)) = B % Assign B to "1" locations in A
It give you what you asked for.
0 Commenti
Più risposte (3)
Matt J
il 30 Giu 2019
Modificato: Matt J
il 1 Lug 2019
[i,j]=find(A(:));
result=accumarray([i,j],B(:),size(A.')).'
4 Commenti
Image Analyst
il 1 Lug 2019
I think it's because the poster did not see what she wanted to see. So instead of seeing:
0 1 2 3 0 0 4 5 0 6
like she asked for, you see
result =
(1,2) 1
(1,3) 2
(1,4) 3
(1,7) 4
(1,8) 5
(1,10) 6
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!