필터 지우기
필터 지우기

Combining two arrays by pointwise repeating the elements of A(i), B(i) times.

조회 수: 1 (최근 30일)
Michel
Michel 2014년 10월 9일
편집: Matt J 2014년 10월 9일
I want to combine two vectors (A and B) with the same length into a new vector (C) with length sum of B.
e.g.
A = [1,2,3,4]; B = [2,1,2,3];
C = [1,1,2,3,3,4,4,4]
Thus repeating the elements of A, B times.

답변 (2개)

Pierre Benoit
Pierre Benoit 2014년 10월 9일

Matt J
Matt J 2014년 10월 9일
편집: Matt J 2014년 10월 9일
idx(cumsum([1,B]))=ones(length(A)+1,1);
C=A(cumsum(idx(1:end-1)))

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by