How do I assign a vector to a logical matrix?

I currently have a logical matrix A representing a system's pupil. The matrix is 28x37, with 210 of the elements being logically true.
I also have vector B, of size 1x210.
I wish to assign the values of vector B to the true elements of matrix A, such that the result will be a 28x37 matrix with the values of vector B shown in the system's pupil.
I can use loops to scan for posisitve elements and then assign values to each element individually, but I sense there is a quicker way.
Any help would be much appreciated!

 Accepted Answer

AA=zeros(size(A),'like',B)
AA(A)=B;
A=AA;
clear AA

More Answers (0)

Products

Asked:

on 19 Aug 2020

Commented:

on 19 Aug 2020

Community Treasure Hunt

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

Start Hunting!