How to Vecrorizing conditional vactor mapping problem?

1 回表示 (過去 30 日間)
Omar Ali Muhammed
Omar Ali Muhammed 2021 年 3 月 6 日
回答済み: Omar Ali Muhammed 2021 年 3 月 6 日
Dear, A is a binary vector its values correspond to the number of times to repeat the corresponding number drawn from the vector B. 0 value in A means copying value from B to C while 1 value in A means representing the corresponding value in B by 3 bits.
as an example: A=[0 1 0 0 0 1]; B=[0 1 0 1 0 0]; C=[0 0 0 1 0 1 0 0 0 0] Can we avoid using classical loop? Regards

採用された回答

Omar Ali Muhammed
Omar Ali Muhammed 2021 年 3 月 6 日
r=A.*3;
r(r==0)=1;
t1=repelem(B,r);
t2=repelem(A,r);
t3=t1.*t2;
t3=dec2bin(t3)'
c=regexprep(t3,'111','001');
c=c-'0';
c(t2==0)=t1(t2==0)
Results:
c =
0 0 0 1 0 1 0 0 0 0
Is there any faster execution?

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGain Scheduling についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by