필터 지우기
필터 지우기

Find largest array size in cell of many arrays

조회 수: 43 (최근 30일)
RuiQi
RuiQi 2016년 6월 17일
댓글: Image Analyst 2020년 1월 17일
I have a cell each cell storing a different sized array. How do i find the largest width and height of all the arrays ?
I tried
size(test{:}(:,1,1))
test is my cell. so meaning for all test, find the size of (:,1,1). But it is wrong of coz so help me thanks.
Like
cell{1} = 10x10 uint8
cell{2} = 10x11
cell{3} = 5x99
so
min_size_of_cell_array(cell{:}) = 5,10
like that
  댓글 수: 1
Stephen23
Stephen23 2016년 6월 17일
Have a look at cellfun: it has some handy features that you can use:
>> C{1} = NaN(10,10);
>> C{2} = zeros(10,11);
>> C{3} = ones(5,99);
>> cellfun('size',C,1) % rows
ans =
10 10 5
>> cellfun('size',C,2) % columns
ans =
10 11 99

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 6월 17일
C = arrayfun(@(x)rand(randi([1 20],1,2)),(1:8)','un',0);% example
[s,d] = cellfun(@size,C);
out = max([s,d]);
  댓글 수: 2
RuiQi
RuiQi 2016년 6월 17일
Thanks ! The cellfun is really useful !
Avik Mahata
Avik Mahata 2019년 1월 13일
How do I convert the maximum cellarray to matrix after identifying the particular cell array?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

shashmitha lakshmi
shashmitha lakshmi 2020년 1월 16일
How to find the maxmimum length array between two arrays
  댓글 수: 1
Image Analyst
Image Analyst 2020년 1월 17일
Try this:
% Create our data, a cell array of vectors of random lengths.
for k = 1 : 100
thisLength = randi(50); % Anywhere from 1 to 50.
ca{k} = rand(1, thisLength); % Create row vector of this length.
end
% Now that data has been created,
% find the lengths of all the elements.
allLengths = cellfun(@length, ca)
% Now find the longest vector between element 15 and 35 (for example)
maxLength = max(allLengths(15:35))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by