How to extract the max items in struct?

Hello there, I have a struct of faces and vertices, how to extract the item that has the maximum faces and vertices?

2 Comments

What do you mean with maximum?
for example, here the max faces and vertices are field number 1

Sign in to comment.

 Accepted Answer

OCDER
OCDER on 2 Aug 2018
Edited: OCDER on 2 Aug 2018
When you say "max", did you mean "max number of elements" or "max value within a vector"? Did you want something like this?
for j = 1:10 %Just creating a test case structure
A(j,1) = struct('faces', zeros(1, randi(1000)), ...
'vertices', zeros(1, randi(1000)));
end
Faces = cellfun('length', {A.faces});
Vertices = cellfun('length', {A.vertices});
MaxIdx = find(Faces == max(Faces) & Vertices == max(Vertices));

2 Comments

The output may be empty or nonscalar.
Thank you very much you saved my life ♥

Sign in to comment.

More Answers (0)

Categories

Find more on Surfaces, Volumes, and Polygons in Help Center and File Exchange

Asked:

on 2 Aug 2018

Commented:

on 5 Sep 2018

Community Treasure Hunt

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

Start Hunting!