Find smallest cell in cell array

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 19 Apr. 2012

2 Stimmen

What is "size" in this context? Number of rows? Number of columns? Number of elements? Storage requirement?
Which is smaller:
'fdoafodsif-0dsi0-0-dfs0-fds0--ds'
or
struct('foo',3,'bar',7)
?

4 Kommentare

Philip
Philip am 19 Apr. 2012
Apologies, I should definitely have made this clearer! I mean, the number of columns of each cell. Some cells are 1x128, for example, whilst some are 1x64... I would like to find the smallest cell in the cell array, so it should return 1x64 in this example.
Walter Roberson
Walter Roberson am 19 Apr. 2012
[minsize, minidx] = cellfun(@(C) size(C,2), YourCell);
Philip
Philip am 19 Apr. 2012
That worked perfectly, thanks so much!
Jan
Jan am 19 Apr. 2012
Or slightly faster:
[minsize, minidx] = min(cellfun('size', YourCell, 2));

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by