Copy range of values from all fields in a structure to another structure
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
kevin
el 14 de Dic. de 2015
Comentada: kevin
el 14 de Dic. de 2015
Lets say I have the following struct: data = FIELD1: [1x250 double] FIELD2: [1x250 double]
I want to copy the range (25:50) from both fields into a new struct where the result would look like new = FIELD1: [1x26 double] FIELD2: [1x26 double] I know I can do this in a loop using fieldnames but would like to find a more direct approach.
0 comentarios
Respuesta aceptada
Walter Roberson
el 14 de Dic. de 2015
newStruct = structfun(@(V) V(25:50), oldStruct, 'Uniform', 0);
No explicit loop needed.
Más respuestas (0)
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!