finding max value in a matrix
古いコメントを表示
I have a matrix with 5 columns and one million rows. How can I find the max value of every 60 rows in that rows of million
採用された回答
その他の回答 (1 件)
I would split the matrix into a cell array of 60 rows with mat2cell and then use cellfun (or a loop) to find the max of each cell:
numsplit = ceil(size(m, 1) / 60); %how many cells are needed
rowdist = ones(1, numsplit) * 60; %define the row split
rowdist(end) = mod(size(m, 1), 60); %adjust last distance to be the modulo of row by 60
c = mat2cell(m, rowdist, size(m, 2)); %create a cell array where each cell is 60 rows
if isempty(c{end}) %will happen when size(m, 1) is a multiple of 60
c(end) = [];
end
mx = cellfun(@(mm) max(mm(:)), c);
4 件のコメント
mx = cellfun(@(mm) max(mm(:)), mat2tiles(m,60,1));
It probably should read:
mx = cellfun(@(mm) max(mm(:)), mat2tiles(m,60,Inf));
Matt J
2014 年 9 月 28 日
If that's what the OP intended, then yes. You could also do
mx = cellfun(@(mm) max(mm(:)), mat2tiles(m,60) );
Jan
2014 年 10 月 12 日
You do not need the indirection over a cell. A 3D array is enough and much faster.
カテゴリ
ヘルプ センター および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!