필터 지우기
필터 지우기

How do I defined this (cell) array?

조회 수: 3 (최근 30일)
Maroulator
Maroulator 2014년 12월 10일
답변: Star Strider 2014년 12월 10일
I am trying to define a cell array (or whatever other array), such that y has the following 11 elements.
[], X.0, X.1, X.2, X.3, X.4, X.5, X.6, X.7, X.8, X.9
Is there an easier way to do this other than resorting to the following?
y{1,1}=' ';
y{1,2}='X.0';
y{1,3}='X.1';
y{1,4}='X.2';
y{1,5}='X.3';
y{1,6}='X.4';
y{1,7}='X.5';
y{1,8}='X.6';
y{1,9}='X.7';
y{1,10}='X.8';
y{1,11}='X.9';
I also tried the genvarname command, but it seems that the dot between the X and the numerical figure is throwing it off.

채택된 답변

the cyclist
the cyclist 2014년 12월 10일
Here is a straightforward way:
y{1,1}=' ';
for n = 2:11
y{1,n} = ['X.',num2str(n-2)]
end

추가 답변 (1개)

Star Strider
Star Strider 2014년 12월 10일
This works:
y = {strsplit([' ' sprintf('X.%-d\n', 0:9)])};
y = y{1}(1:11)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by