renameFields

버전 1.0.0 (4.19 KB) 작성자: Paul Shoemaker
Utility to rename all fields in a structure (or character array) using several different naming conventions.
다운로드 수: 33
업데이트 날짜: 2018/7/28

라이선스 보기

% renameFields Utility to rename fields in a structure (or character array)
%
% OUTPUT = renameFields(INPUT,OPERATION) modifies the fields in INPUT using
% the requested operation(s) (valid operations listed below). INPUT can be a
% structure, in which case the OUTPUT is a structure whos fields have been
% renamed according to the specified operation(s). Field order is respected
% and retained. INPUT can also be a character array or cell array of
% character arrays, in which case the OUTPUT is a modified array of the same
% size/form as the INPUT, but with the arrays modified according to the
% requested operation(s).
%
% renameFields(STRUCT,OLDNAMES,NEWNAMES) will return a structure where the
% OLDNAMES have been replaced with NEWNAMES. The nth element of OLDNAMES
% corresponds to the nth element of NEWNAMES, which means that OLDNAMES and
% NEWNAMES must have the same number of elements. Calling renameFields with
% three arguments is limited to STRUCT inputs, unlike calling it with two
% arguments, which permits character strings or cell arrays of character
% strings.
%
%
% Example: Make all fields upper-case
% data = struct('variable_one',1,'VariableTwo',2,'variable_Three',3,...
% 'VARIABLE_four',4,'variableFive_',5,'variable6',6,...
% 'variableSEVEN',7,'Variable8and9',[8 9]);
% newData = renameFields(data,'upper');
%
%
% Example: Make all fields use Pascal convention, then trim trailing '_'
% data = struct('variable_one',1,'VariableTwo',2,'variable_Three',3,...
% 'VARIABLE_four',4,'variableFive_',5,'variable6',6,...
% 'variableSEVEN',7,'Variable8and9',[8 9]);
% newData = renameFields(data,{'pascal' 'trim'});
%
%
% Example: Remove spaces/punc., apply underscore and capitalize each word .
% myString = 'You know, a sentence could also be provided… now that would be cool!';
% newString = renameFields(myString,{'underscore' 'no punc' 'first upper'})
%
% Note that the order of operations matters in the above example. Punctuation
% cleansing is done last because having punctuation is useful in identifying
% words/chunks for the other operations.
%
%
% Programmed and Copyright by Paul Shoemaker: www.matlabinvesting.com

인용 양식

Paul Shoemaker (2024). renameFields (https://www.mathworks.com/matlabcentral/fileexchange/68349-renamefields), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2018a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Variables에 대해 자세히 알아보기
태그 태그 추가

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0