Average across the fields of a structure when each field contains a single value
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Josh Tome
el 13 de Feb. de 2023
Comentada: Stephen23
el 13 de Feb. de 2023
Hello,
I have a structure (Sway_dist_COP_Sag) with 3 fields, each containing a single value that I would like to average together. Please see image below. I would like the end result to be in the 2.15 range.
Thanks in advance.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1294495/image.jpeg)
0 comentarios
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 13 de Feb. de 2023
Try this
% Extract all values for each field into row vectors.
v1 = [Sway_dist_COP_Sag.Con1Pre00standop01]
v2 = [Sway_dist_COP_Sag.Con1Pre00standcl02]
v3 = [Sway_dist_COP_Sag.Con1Pre00stand05_1plate]
% Take the mean of all 3 row vectors strung together.
theMean = mean([v1, v2, v3])
4 comentarios
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!