Find maxima every n positions in 3D matrix

조회 수: 2 (최근 30일)
Chris
Chris 2017년 9월 11일
댓글: Chris 2017년 9월 11일
Hello! I have a 500x400x120 matrix. I need to get the maximum values of every 12 steps in the 3rd dimension, so to end up with a 500x400x10 matrix. I tried
max(matrix(:,:,1:12:end),[],3)
but it gives me a 500x400 matrix as a result. Any ideas? Thanks in advance!
  댓글 수: 2
James Tursa
James Tursa 2017년 9월 11일
Do you mean max of matrix(:,:,1:12) across the 3rd dimension being the first 2D matrix, then the max of matrix(:,:,13:24) across the 3rd dimension being the next 2D matrix, etc?
Chris
Chris 2017년 9월 11일
Yeah, exactly!

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2017년 9월 11일
Do that 10 times but with the indexes correct:
means = zeros(500, 400, 10);
for k = 1 : 10
z1 = (k - 1) * 12 + 1;
z2 = z1 + 11;
means(:, :, k) = max(matrix(:,:, z1:z2), [], 3);
end

추가 답변 (1개)

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2017년 9월 11일
Here's one with while loop. There's probably a faster way.
stepsize = 12; count = 1; i=1;
while i<=size(mymatrix,3)
mymaxmatrix(:,:,count) = max(mymatrix(:,:,i:i+stepsize-1),[],3);
count = count+1; i=i+stepsize;
end

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by