How to find the maximum length in a structure of vectors?

20 views (last 30 days)
I have a struct, fem. One of its field is a cell (fem.Element) and I want to find the maximum length of fem.Element.
Thanks in advance, André

Accepted Answer

AXL on 12 Nov 2017
I solved using this: max(cellfun(@length,fem.Element);

More Answers (1)

Precise Simulation
Precise Simulation on 12 Nov 2017
If by "maximum length" you mean the number of struct entries, then you can just use one of the standard length, numel, or size commands
If you mean the maximum value in each struct entry you could use something like
mx_all = cellfun(@max,struct2cell(fem))
mx = max(mx_all(:))
AXL on 12 Nov 2017
I solved it using this: max(cellfun(@length,fem.Element);
But really thanks! I'm not used to work with cells.

Sign in to comment.


Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!