renameFields

Utility to rename all fields in a structure (or character array) using several different naming conventions.
33 descargas
Actualizado 28 jul 2018

Ver licencia

% 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

Citar como

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

Compatibilidad con la versión de MATLAB
Se creó con R2018a
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Variables en Help Center y MATLAB Answers.
Etiquetas Añadir etiquetas

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
1.0.0