MATLAB Answers

extract logical locations that match array

1 view (last 30 days)
ALDO on 9 Oct 2019
Commented: ALDO on 9 Oct 2019
Hi I know this might be simple but i have a logical array and another double arry with the same length. I want to extract the value of the locations in array two that correspond to to 1 in the logical array.
A=1 0 1 1 0
B= 77 5 2 8 9
I did the following
but it only gives me D= 77 2 8. I want the result to include zero for the locations that dont match. so ans would be D= 77 0 2 8 0
I would appriciate any help on this! Thanks in advance!


Sign in to comment.

Accepted Answer

Adam on 9 Oct 2019
B .* A
would seem to give what you want

  1 Comment

ALDO on 9 Oct 2019
Thank you so much. worked perfectly!

Sign in to comment.

More Answers (0)