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!

 채택된 답변

Steve Eddins
Steve Eddins 2021년 1월 12일

1 개 추천

C = zeros(size(B));
C(logical(B)) = A

댓글 수: 2

Thanks it's a very elegant solution!
In addition to the doc link that provided, see my 28-Jan-2008 blog post on the topic.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bruno Luong
Bruno Luong 2021년 1월 12일
편집: Bruno Luong 2021년 1월 12일

1 개 추천

Result = zeros(size(B));
Result(B==1)=A

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

질문:

2021년 1월 12일

댓글:

2021년 1월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by