주요 콘텐츠

addcats

R2026b

categorical형 배열에 범주 추가

설명

B = addcats(A,newcats)는 categorical형 배열에 범주를 추가합니다. 기본적으로 addcats는 categories(A)의 출력값에서 볼 수 있듯이 범주 집합의 끝에 새 범주를 추가합니다. 새 요소를 추가하지는 않습니다. 출력된 categorical형 배열 B에는 새 범주에 속하는 요소를 B에 할당할 때까지 해당 요소가 포함되지 않습니다.

A가 순서형 categorical형 배열인 경우 Before 또는 After 이름-값 인수를 지정해야 합니다.

예제

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

예제

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

예제

모두 축소

categorical형 배열을 만듭니다.

A = categorical(["red" "blue" "red" "blue" "red" "blue"])
A = 1×6 categorical
     red      blue      red      blue      red      blue 

배열의 범주를 표시합니다.

categories(A)
ans = 2×1 cell
    {'blue'}
    {'red' }

범주 green과 범주 black을 범주 집합의 끝에 추가합니다. 새 배열에는 동일한 요소가 있지만 더 많은 범주가 있습니다.

B = addcats(A,["green" "black"])
B = 1×6 categorical
     red      blue      red      blue      red      blue 

categories(B)
ans = 4×1 cell
    {'blue' }
    {'red'  }
    {'green'}
    {'black'}

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

A = categorical(["medium" "large"; "small" "xlarge"; "large" "medium"], ...
                ["small" "medium" "large" "xlarge"], ...
                Ordinal=true)
A = 3×2 categorical
     medium      large  
     small       xlarge 
     large       medium 

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

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

small 앞에 범주 xsmall을 추가합니다. 그런 다음 새 배열의 범주를 표시합니다. 배열의 범주에 수학적 정렬인 xsmall < small < medium < large < xlarge가 적용됩니다.

B = addcats(A,"xsmall",Before="small");
categories(B)
ans = 5×1 cell
    {'xsmall'}
    {'small' }
    {'medium'}
    {'large' }
    {'xlarge'}

입력 인수

모두 축소

입력 배열로, categorical형 배열로 지정됩니다.

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

범주의 이름으로, string형 스칼라 또는 문자형 벡터로 지정됩니다.

출력 인수

모두 축소

추가된 범주를 갖는 출력 배열로, categorical형 배열로 반환됩니다.

확장 기능

모두 확장

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

GPU 코드 생성
GPU Coder™를 사용하여 NVIDIA® GPU용 CUDA® 코드를 생성할 수 있습니다.

버전 내역

R2013b에 개발됨