How to get the smallest value in submatrices
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I would appreciate if you could help me with this problem.
I have a big matrix , where are submatrices of the same size.
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.
0 个评论
采纳的回答
Bruno Luong
2021-10-2
B=randi(9,10,2)
[m,n] = size(B);
k = 5;
if mod(m,k)
error('m must divisible by k');
end
minsub = min(reshape(B,[m/k k n]),[],[1 3]).'
更多回答(1 个)
Kevin Holly
2021-10-2
cellfun(@min,B,'UniformOutput',false)
%or
cellfun(@min,cellfun(@min,B,'UniformOutput',false),'UniformOutput',false)
6 个评论
Kevin Holly
2021-10-2
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!