# hi every one, i need to ask a question, thank you

1 view (last 30 days)
mina massoud on 30 Jun 2019
Commented: mina massoud on 1 Jul 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

Image Analyst on 30 Jun 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.

Matt J on 30 Jun 2019
Edited: Matt J on 30 Jun 2019
result=sparse(1,find(A),B)

Catalytic on 30 Jun 2019
A=double(A);
A(logical(A))=B;

Matt J on 30 Jun 2019
Edited: Matt J on 1 Jul 2019
[i,j]=find(A(:));
result=accumarray([i,j],B(:),size(A.')).'
mina massoud on 1 Jul 2019
sorry i accept it by mistake , now i accept your answer that is the best answer
thank's very much for all of you, i really appraciate it

### Categories

Find more on Descriptive Statistics in Help Center and File Exchange

R2019a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!