필터 지우기
필터 지우기

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.

채택된 답변

Walter Roberson
Walter Roberson 2018년 12월 10일
편집: Walter Roberson 2018년 12월 10일
repelem(x, round(y))
  댓글 수: 7
Walter Roberson
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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by