how to display a value in first column the second column number of times?
조회 수: 1 (최근 30일)
이전 댓글 표시
suppose i have a column vector x=[1 2 3 4]; and y=[2 3 3.5 4]
i want the output as xy=[1 1 2 2 2 3 3 3 3 4 4 4 4];
the number 3.5 can be rounded off to a whole number. here ive taken it as 4.
댓글 수: 0
채택된 답변
Walter Roberson
2018년 12월 10일
편집: Walter Roberson
2018년 12월 10일
repelem(x, round(y))
댓글 수: 7
Walter Roberson
2018년 12월 10일
cell2mat(arrayfun(@(v, n) v(ones(n,1)), x, round(y), 'uniform', 0)) %assumes inputs are column vectors
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!