Main Content

DimensionNames 속성에 대한 R2016b에서의 변경 사항

table 데이터형은 열 방향, 이종 데이터를 단일 컨테이너로 모으기에 적합한 데이터형입니다. 테이블에는 변수 이름, 행 이름, 차원 이름, 설명, 변수 단위와 같은 메타데이터 속성도 포함됩니다. R2016b부터는 차원 이름을 사용하여 점 첨자로 테이블 데이터와 메타데이터에 액세스할 수 있습니다. 이를 위해서는 차원 이름이 변수 이름과 동일한 요구 사항을 충족해야 합니다. 이전 버전과의 호환성을 위해 테이블은 필요한 경우 차원 이름을 자동으로 수정하여 이러한 제한 사항을 적용합니다.

행 이름과 변수 이름이 포함된 테이블을 생성합니다.

Number = [8; 21; 13; 20; 11];
Name = {'Van Buren'; 'Arthur'; 'Fillmore'; 'Garfield'; 'Polk'};
Party = categorical({'Democratic'; 'Republican'; 'Whig'; 'Republican'; 'Republican'});
T = table(Number,Party,'RowNames',Name)
T = 

                 Number      Party   
                 ______    __________

    Van Buren     8        Democratic
    Arthur       21        Republican
    Fillmore     13        Whig      
    Garfield     20        Republican
    Polk         11        Republican

차원 이름 등의 차원의 속성을 표시합니다. 차원 이름의 디폴트 값은 'Row''Variables'입니다.

T.Properties
ans = 

  struct with fields:

             Description: ''
                UserData: []
          DimensionNames: {'Row'  'Variables'}
           VariableNames: {'Number'  'Party'}
    VariableDescriptions: {}
           VariableUnits: {}
                RowNames: {5×1 cell}

R2016b부터는 차원 이름에 새 이름을 할당하고, 이 이름을 사용하여 테이블 데이터에 액세스할 수 있습니다. 차원 이름은 유효한 MATLAB® 식별자여야 하며, 예약어인 'Properties', 'RowNames', 'VariableNames'가 아니어야 합니다.

첫 번째 차원 이름에 새 이름을 할당하고, 이 이름을 사용하여 테이블의 행 이름에 액세스합니다.

T.Properties.DimensionNames{1} = 'Name';
T.Name
ans =

  5×1 cell array

    'Van Buren'
    'Arthur'
    'Fillmore'
    'Garfield'
    'Polk'

Name이라는 새 테이블 변수를 생성합니다. 이 변수를 생성하면 충돌을 방지하기 위해 테이블의 첫 번째 차원 이름이 수정됩니다. 업데이트된 차원 이름은 Name_1이 됩니다.

T{:,'Name'} = {'Martin'; 'Chester'; 'Millard'; 'James'; 'James'}
Warning: DimensionNames property was modified to avoid conflicting dimension and variable names: 
 'Name'. See Compatibility Considerations for Using Tables for more details. This will become an  
error in a future release. 

T = 

                 Number      Party         Name   
                 ______    __________    _________

    Van Buren     8        Democratic    'Martin' 
    Arthur       21        Republican    'Chester'
    Fillmore     13        Whig          'Millard'
    Garfield     20        Republican    'James'  
    Polk         11        Republican    'James'  
T.Properties.DimensionNames
ans =

  1×2 cell array

    'Name_1'    'Data'

마찬가지로, 유효한 MATLAB 식별자가 아닌 차원 이름을 할당할 경우에도 이름이 수정됩니다.

T.Properties.DimensionNames{1} = 'Last Name';
T.Properties.DimensionNames
Warning: DimensionNames property was modified to make the name 'Last Name' a valid MATLAB
identifier. See Compatibility Considerations for Using Tables for more details. This will  
become an error in a future release. 

ans =

  1×2 cell array

    'LastName'    'Data'

R2016b에서는 차원 이름이 유효한 식별자가 아니거나 변수 이름 또는 예약된 이름과 충돌하는 경우 테이블에서 경고가 발생하므로, 이전 릴리스에서 생성된 코드와 테이블로 계속 작업할 수 있습니다. 이러한 경고가 발생하는 경우, 이를 방지하기 위해 코드를 업데이트하는 것이 좋습니다.