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.
ダウンロード: 34
更新 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 (2025). renameFields (https://www.mathworks.com/matlabcentral/fileexchange/68349-renamefields), MATLAB Central File Exchange. に取得済み.

MATLAB リリースの互換性
作成: R2018a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersVariables についてさらに検索
タグ タグを追加

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.0.0