For example I have this matrix(3x3) and I want to make a new 2x2 matrix with the max values from all the submatrixes :
= [
5 4 6
3 2 3
8 8 9
first submatrix:
[5 4
3 2 ]
max value=5
second submatrix:
[4 6
2 3]
max value=6
third submatrix:
[3 2
8 8 ]
max value=8
fourth submatrix:
[2 3
8 9]
max value=9
and I want to get this matrix(2x2) that has all the max values as elements of the previous submatrixes:
NewA=[5 6
8 9]
One last thing the only thing you can use are basic things like for loops if statements....(simple solutions,begginer solutions) Also you can't use the max function,you have to write the code for that,and the solution should work for every square matrix
Using the Image Processing Toolbox
How it works:
im2col(A, block_size, 'sliding')arranges each sliding submatrix of sizeblock_sizeas a column;max(..., [], 1)takes the maximum of each column;reshape(..., size(A)-block_size+1)reshapes the result into a matrix of the appropriate size.Note that steps 1 and 3 both use column-major order, so the maxima in the result are arranged consistently with the input data.
Without the toolbox
Using linear indexing and implicit expansion,
im2col's behaviour can be emulated as follows:The three variables
ind_base,ind_cornerandind_colshave the following interpretation:ind_basedefines the linear indices of the first (uppermost, leftmost) submatrix;ind_cornerdefines the linear indices of the upper-left corner of each submatrix;ind_colscontains the linear indices of each submatrix arranged as columns.