renameFields

版本 1.0.0 (4.2 KB) 作者: Paul Shoemaker
Utility to rename all fields in a structure (or character array) using several different naming conventions.
34.0 次下载
更新时间 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