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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by