Sliding max window and its average for multi-dimensional arrays

后端 未结 3 1290
暖寄归人
暖寄归人 2021-02-08 08:59

I have a 60 x 21 x 700 matrix, where the 60 x 21 represent a pressure output x number of frames. I want to find the 2 x

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-08 09:25

    One other approach using im2col

    %// getting each 2x2 sliding submatrices as columns
    cols = im2col(A,[2 2],'sliding'); 
    
    %// getting the mean & reshaping it to 2D matrix
    C = reshape(mean(cols),size(A,1)-1,[]); 
    
    %// to find the maximum of the sub-matrix-means and its corresponding index.
    [B,i] = max(mean(cols)); 
    
    %// reshaping the corresponding sub-matrix to 2D matrix
    mat = reshape(cols(:,i),2,2); 
    

    Results:

    >> mat
    
    mat =
    
     6    10
     8     9
    
    >> C
    
    C =
    
    1.5000    1.5000    1.5000    1.5000
    2.0000    2.2500    2.7500    2.7500
    2.0000    3.7500    6.0000    5.5000
    1.7500    4.5000    8.2500    7.2500
    
    >> B
    
    B =
    
    8.2500
    

提交回复
热议问题