Get the max value and the indices of max value across a series of matrices
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Anwar S
am 20 Aug. 2018
Kommentiert: Anwar S
am 20 Aug. 2018
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194099/image.png)
I have a 25x50 matrix each having another 128x128 matrix in each cell. Now I want to create a 25x1 matrix that will have a 128x128 matrix in each cell containing the maximum value across those eleven 128x128 matrices in each row. I also need the index of that cell from which the maximum value came from.
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 20 Aug. 2018
Let A - your cell array (25 x 50) with double matrix 128 x 128.
n = size(A,1);
maxvalue = cell(n,1);
maxidx = cell(n,1);
for ii = 1:n
[maxvalue{ii},maxidx{ii}] = max(cat(3,A{ii,:}),[],3);
end
Weitere Antworten (1)
Julie
am 20 Aug. 2018
BigMat=cellfun(@(x) cat(3,DATA{:,x}),num2cell(1:25),'UniformOutput',false)
[maxVal idx] = cellfun(@(x) max([BigMat{x}],[],3),num2cell(1:25),'UniformOutput',false)
BigMat is all of the columns concatenated into 3D matrices (use DATA{x,:} for rows instead). Then the value and indices are found using max.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!