Main Content

addcats

categorical형 배열에 범주 추가

설명

예제

B = addcats(A,newcats)는 입력 categorical형 배열 A의 범주 목록 끝에 범주를 추가합니다. 출력된 categorical형 배열 B에 포함된 값은 A와 동일합니다. 출력값 B에는 newcats에서 B의 요소로 값을 할당할 때까지 새 범주와 동일한 요소가 추가되지 않습니다.

A가 순서형 categorical형 배열인 경우 'Before',beforewhere 입력 인수나 'After',afterwhere 입력 인수를 지정해야 합니다.

예제

B = addcats(A,newcats,'Before',beforewhere)beforewhere로 지정한 범주의 앞에 새 범주를 추가합니다.

B = addcats(A,newcats,'After',afterwhere)afterwhere로 지정한 범주의 뒤에 새 범주를 추가합니다.

예제

모두 축소

비순서형 categorical형 배열을 만듭니다.

A = categorical({'republican' 'democrat' 'republican';...
    'democrat' 'republican' 'democrat'})
A = 2x3 categorical
     republican      democrat        republican 
     democrat        republican      democrat   

A의 범주를 표시합니다.

categories(A)
ans = 2x1 cell
    {'democrat'  }
    {'republican'}

A는 2개의 범주로 이루어진 2×3 categorical형 배열입니다.

범주 independent와 범주 undeclared를 범주 목록의 끝에 추가합니다.

B = addcats(A,{'independent' 'undeclared'})
B = 2x3 categorical
     republican      democrat        republican 
     democrat        republican      democrat   

B에 포함된 값은 A와 동일합니다.

B의 범주를 표시합니다.

categories(B)
ans = 4x1 cell
    {'democrat'   }
    {'republican' }
    {'independent'}
    {'undeclared' }

B는 4개의 범주로 이루어진 2×3 categorical형 배열입니다.

순서형 categorical형 배열을 만듭니다.

A = categorical({'medium' 'large'; 'small' 'xlarge'; 'large' 'medium'},...
    {'small' 'medium' 'large' 'xlarge'},'Ordinal',true)
A = 3x2 categorical
     medium      large  
     small       xlarge 
     large       medium 

A의 범주를 표시합니다.

categories(A)
ans = 4x1 cell
    {'small' }
    {'medium'}
    {'large' }
    {'xlarge'}

A가 순서형 배열이므로, 이 배열의 범주에는 수학적 정렬(Mathematical Ordering)인 small < medium < large < xlarge가 적용됩니다.

small 앞에 범주 xsmall을 추가합니다.

B = addcats(A,'xsmall','Before','small')
B = 3x2 categorical
     medium      large  
     small       xlarge 
     large       medium 

B에 포함된 값은 A와 동일합니다.

B의 범주를 표시합니다.

categories(B)
ans = 5x1 cell
    {'xsmall'}
    {'small' }
    {'medium'}
    {'large' }
    {'xlarge'}

범주에 수학적 정렬인 xsmall < small < medium < large < xlarge가 적용됩니다.

입력 인수

모두 축소

categorical형 배열로, 벡터, 행렬, 다차원 배열 중 하나로 지정됩니다.

새 범주로, 문자형 벡터, 문자형 벡터로 구성된 셀형 배열 또는 string형 배열로 지정됩니다.

앞에 위치할 범주로, 문자형 벡터 또는 string형 스칼라로 지정됩니다.

뒤에 위치할 범주로, 문자형 벡터 또는 string형 스칼라로 지정됩니다.

확장 기능

C/C++ 코드 생성
MATLAB® Coder™를 사용하여 C 코드나 C++ 코드를 생성할 수 있습니다.

버전 내역

R2013b에 개발됨