How to get the smallest value in submatrices
Afficher commentaires plus anciens
Hi,
I would appreciate if you could help me with this problem.
I have a big matrix
, where
are submatrices of the same size.
, where I want to get a vector containing the smallest elements in each submatrices. I want to avoid for loop as it might slow down my whole program.
Thanks.
Réponse acceptée
Plus de réponses (1)
Kevin Holly
le 2 Oct 2021
cellfun(@min,B,'UniformOutput',false)
%or
cellfun(@min,cellfun(@min,B,'UniformOutput',false),'UniformOutput',false)
6 commentaires
Hung Dao
le 2 Oct 2021
Kevin Holly
le 2 Oct 2021
Modifié(e) : Kevin Holly
le 2 Oct 2021
Yes, so something like this:
B = {rand(1,4);rand(3,5);rand(4,5);rand(9,1);rand(2,4)}
cellfun(@min,B,'UniformOutput',false)
%or
cellfun(@min,cellfun(@min,B,'UniformOutput',false),'UniformOutput',false)
This method allows you to find the minimum even if the submatrices where not the same size.
Hung Dao
le 2 Oct 2021
Hung Dao
le 2 Oct 2021
Kevin Holly
le 2 Oct 2021
I was under the impression that you already had a big matrix B that contained submatrices. If this is not the case, how are your data organized? Are all the matrices in a folder/workspace individually?
Hung Dao
le 2 Oct 2021
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!