Fast calculation of min for a cell array?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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}
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?
0 commentaires
Réponse acceptée
Stephen23
le 10 Nov 2020
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!