필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Creating an array by repeating the index of a cell by the length of the cell

조회 수: 1 (최근 30일)
Ryan Waite
Ryan Waite 2017년 4월 27일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a cell array of data shown below. I would like to create a new array (output) where the index of the cell is repeated "x" times. Where "x" is equal to the length of that specific cell. I can do this with for loops, but can it be done with a simple function?
data = {[1,2,3], [4,5], [6], [7,8,9,10]}
% output = [1,1,1,2,2,3,4,4,4,4]

답변 (1개)

John Malik
John Malik 2017년 4월 28일
repelem(1:length(data), cellfun(@length, data))

이 질문은 마감되었습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by