필터 지우기
필터 지우기

Change a variable name in a dataset array

조회 수: 7 (최근 30일)
dk
dk 2011년 10월 14일
I would like to change the name of one of the variable names in a dataset array. I can do it like this
temp=get(DS);
vn=temp.VarNames;
vn{3}='new name';
set(DS,'VarNames',vn);
Is there an easier way to do this?

채택된 답변

Peter Perkins
Peter Perkins 2011년 10월 14일
There is an easier way:
DS.Properties.VarNames{3} = 'NewName';
DS.Properties holds the array's metadata: variable and observation names, variable units and descriptions, and a description for the array itself, among others. You can see all that by typing
DS.Properties
BTW, there are two problems with the code as you've written it:
1) 'new name' isn't a valid MATLAB identifier, and so not a valid dataset variable name, and 2) calling set without assigning to something has no effect -- dataset arrays are not handles. You'd need to do this:
DS = set(DS,'VarNames',vn);
which is somewhat non-intuitive, and so you're better off accessing the metadata directly through .Properties.
Hope this helps.

추가 답변 (1개)

dk
dk 2011년 10월 14일
I knew there should be an easier way. Thanks

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by