How to Speedup conditional vector elements replacement?

조회 수: 1 (최근 30일)
Omar Ali Muhammed
Omar Ali Muhammed 2021년 3월 6일
댓글: Omar Ali Muhammed 2021년 3월 6일
Dear,
a is a vector its values correspond to the number of times to repeat the
corresponding number drawn from the vector b. following this rule the result
is a vector c.
as an example:
a=[1 4 1 4 4 1];
b=[1 6 8 3 9 2];
c=[1 6 6 6 6 8 3 3 3 3 9 9 9 9 2]
Is there any vectorization solution for this proplem?
Regards

채택된 답변

per isakson
per isakson 2021년 3월 6일
There is a Matlab function, repelem, that does it.
>> repelem( b, a )
ans =
Columns 1 through 13
1 6 6 6 6 8 3 3 3 3 9 9 9
Columns 14 through 15
9 2
>>

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by