MATLAB: How tho find the max value in a struct

maxstructure

Hi,
I made a 1×1 struct with 5 fields. The struct consists of a column of fields and a column of values. How do I find the highest value? And if found, the field that belongs to this highest value?

Best Answer

[maxval, maxidx] = structfun(@max, YourStructure);
fn = fieldnames(YourStructure);
which_field_had_max = fn{maxidx};