필터 지우기
필터 지우기

Using repmat command to create cell array

조회 수: 1 (최근 30일)
Luffy
Luffy 2012년 7월 7일
I want to create a cell array with a repeating pattern of rgb colors of size n where n is a variable that is determined on the run,
So,I've tried this,
repmat({'red','blue','green','black','cyan','magenta','yellow'}, 1, n);
But this generates array of size 7*n, is there a way to delete those extra values/any other function that does this.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 7월 7일
T = {'red','blue','green','black','cyan','magenta','yellow'};
T(1 + mod( (1:n)-1, length(T) ) )
You could repmat n/7 times but you would have to take precautions in case n was not exactly divisible by 7, and you would have to add on the fractional copy to fill out from the full cycle to n.

카테고리

Help CenterFile Exchange에서 Model Architecture and Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by