find minimum value index across cells

조회 수: 1 (최근 30일)
User05
User05 2015년 5월 12일
댓글: User05 2015년 5월 12일
Hi,
I am trying to find the minimum value across cells and not within a cell. For ex: Input is:
in = cell(1,5);
in(:) = {(zeros(3,3))};
rng('shuffle');
for n=1:5
in{n}(:)=rand(3,3);
end
Now I want to find minimum value for each 3x3 location (out is 3x3 data ie. 9 values) across cells. I also want to find which cell had the minimum value.
Can this be done via cellfun? Can I use cellfun for an across cell operation?
I have tried:
min(in{1:5})
but it gives me too many input arguments
I also tried to see if I can do this element by element and hence I tried to do
min(in{1:n}(1,1))
But that said "bad cell reference operation"
Is there a simple way to do this without using loops?
Thanks

채택된 답변

Guillaume
Guillaume 2015년 5월 12일
편집: Guillaume 2015년 5월 12일
Since you want to find the minimum value across the cells, this implies that the matrices within the cells all have the same size. In that case, why don't you use a single matrix of a larger dimension?
numdims = ndims(in{1}) + 1;
inasmat = cat(numdims, in{:})
[minacross, mincell] = min(inasmat, [], numdims)
cellfun will be of no use for what you want to do.

추가 답변 (0개)

카테고리

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