Fast calculation of min for a cell array?

조회 수: 1 (최근 30일)
Sim
Sim 2020년 11월 10일
댓글: Sim 2020년 11월 10일
Hi, I have this cell array:
A =
3×160 cell array
Columns 1 through 5
{18×10754 double} {18×10754 double} {18×10754 double} {18×10754 double} {18×10754 double}
{31×14797 double} {31×14797 double} {31×14797 double} {31×14797 double} {31×14797 double}
{65×34310 double} {65×34310 double} {65×34310 double} {65×34310 double} {65×34310 double}
and for each of my 160 cells in A(3,:) (i.e. the 160 cells in the third row of A):
A(3,:) =
1×160 cell array
Columns 1 through 5
{65×34310 double} {65×34310 double} {65×34310 double} {65×34310 double} {65×34310 double}
I would need a very fast way to get the min of each column, and therefore such a cell array:
Amin =
1×160 cell array
Columns 1 through 5
{1×34310 double} {1×34310 double} {1×34310 double} {1×34310 double} {1×34310 double}
My attempt is the following:
t1 = tic();
for i = 1 : size(A(3,:),2)
[A_min_value, A_min_row] = min(A{3,i,:},[],1); % (min each column)
Amin_value{3,i,:} = A_min_value;
Amin_row{3,i,:} = A_min_row;
end
dt = toc(t1)
tic-toc time
dt = 0.129487033
Any faster way?

채택된 답변

Stephen23
Stephen23 2020년 11월 10일
nc = size(A,2);
Amin_value = cell(1,nc);
Amin_row = cell(1,nc);
for k = 1:nc
[Amin_value{1,k},Amin_row{1,k}] = min(A{3,k},[],1);
end
  댓글 수: 1
Sim
Sim 2020년 11월 10일
slightly faster and more compact! Thanks a lot :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by