Given a matrix, how can I slice a matrix given the input parameters are the number of rows and number of columns? See example.

1 次查看(过去 30 天)
function [result3Dmatrix] = imgCut(origImgMatrix, numRows, numCols )
For example if matrix is origImgMatrix = [2 4 6 8
9 2 3 4
1 4 9 8
3 9 1 4 ];
And numRows = 2 and numCols = 2. The matrix will be split into 2 rows and 2 columns.
result3Dmatrix will output 4 matrices:
1) 2)
2 4 6 8
9 2 3 4
3) 4)
1 4 9 8
3 9 1 4

回答(1 个)

KSSV
KSSV 2022-4-23
编辑:KSSV 2022-4-23
Read about mat2cell.
origImgMatrix = [2 4 6 8
9 2 3 4
1 4 9 8
3 9 1 4 ];
iwant = mat2cell(origImgMatrix,[2 2],[2 2]) ;
celldisp(iwant)
iwant{1,1} = 2 4 9 2 iwant{2,1} = 1 4 3 9 iwant{1,2} = 6 8 3 4 iwant{2,2} = 9 8 1 4
Also have a look on the function reshape.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by