How determined lowest value in cell?

1 Ansicht (letzte 30 Tage)
jenifer Ask
jenifer Ask am 31 Dez. 2019
Kommentiert: Stephen23 am 1 Jan. 2020
I have cell name as x1
I try to determine the index of my LOOP based on its shortest length.
With the code below I can only index 47 with the longest length.
for K =1: length(x1{i})
...
end
x1 is a sample for 6 images. I have more than 100 images and cannot manually find the smallest value
I try to use:
min(cellfun(@(C)size(C,2),x1{i}))
but error on code.
How do I write it to show the shortest length, 15?

Akzeptierte Antwort

Stephen23
Stephen23 am 31 Dez. 2019
Bearbeitet: Stephen23 am 31 Dez. 2019
For some reason you want to get the number of rows but in your code you check the number of columns. Also your input to cellfun is one numeric array, rather than the entire cell array:
>> min(cellfun(@(C)size(C,1),x1))
ans = 15
  2 Kommentare
jenifer Ask
jenifer Ask am 31 Dez. 2019
How do I get a 6 * 1 vector with the length of points each?
for exemple vector include:
15
22
18
24
15
47
.... To the end.
Stephen23
Stephen23 am 1 Jan. 2020
Simply remove the min:
>> cellfun(@(C)size(C,1),x1)
ans =
15 22 18 24 35 47
Your example seems to be incorrect: the 5th array has 35 rows, not 15 as you wrote.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Max Murphy
Max Murphy am 31 Dez. 2019
x1{i} is a double, so you would use:
length(x1{i})
to get the length of that cell element. If you want to get the minimum length from all the lengths of each cell element, then you would use:
min(cellfun(@length,x1))

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by