Apply a function to a specific field of a structure

This function searches in a structure, and applies a function to all occurrences of a field.
407 descargas
Actualizado 7 jun 2010

Ver licencia

This function searches in the fields of a structure, and applies a given function to all occurrences of a specific field.

© September 30th, 2009, By Reza Farrahi Moghaddam, Synchromedia Lab, ETS, Montreal, Canada

USAGE:
temp_structure = apply_func_on_all_fields_with_name(temp_structure, field_name, func_id, data_bag);
where
temp_structure: The input structure
field_name: The target field name
func_id: The function that will be applied to the target fields
data_bag: (optional) A basket/bag to pass the parameters to the func_id
Outputs
temp_structure: The output structure

Below, an example is provided.
sample_struct.check = 5;
sample_struct.level.check = 4;
sample_struct.level.other = 'a';
sample_struct.level.another.test = 7;
sample_struct.level.another.check = -2;
% apply the 'sqrt' function to the 'check' fields of the structure
sample_struct = apply_func_on_all_fields_with_name(sample_struct, 'check', @sqrt);

Citar como

Reza Farrahi Moghaddam (2024). Apply a function to a specific field of a structure (https://www.mathworks.com/matlabcentral/fileexchange/27848-apply-a-function-to-a-specific-field-of-a-structure), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2007b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Data Types en Help Center y MATLAB Answers.

Community Treasure Hunt

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

Start Hunting!

Apply_function_on_fields_in_structures/

Versión Publicado Notas de la versión
1.0.0.0