get the minimum and the maximum value out of a structure in matlab

Assuming you have a structure myStruct with numeric fields, you can use the structfun and min/max functions to find the minimum and maximum values.

To find the minimum value:

main.m
minValue = min(structfun(@min, myStruct));
43 chars
2 lines

To find the maximum value:

main.m
maxValue = max(structfun(@max, myStruct));
43 chars
2 lines

In both cases, structfun applies the min or max function to each field of the structure, and the outer min or max function finds the minimum or maximum value of all the fields.

Note that if your structure has fields with different lengths, you will need to adjust the code above to handle that case appropriately.

related categories

gistlibby LogSnag