how to extract 2d window from a 2d matrix

3 ビュー (過去 30 日間)
MSP
MSP 2017 年 3 月 31 日
コメント済み: Guillaume 2017 年 3 月 31 日
consider you have a 9/9 matrix 2d.It is required to extract 9 matrixes like the attachment
How to do it by using loops as it will help in further calculations

採用された回答

Guillaume
Guillaume 2017 年 3 月 31 日
編集済み: Guillaume 2017 年 3 月 31 日
No loop needed:
mat2cell(yourmatrix, [3 3 3], [3 3 3])
or you could just reshape the matrix as 3x3x9 and loop over the pages whenever you need access to these 9 matrices:
matrices = reshape(yourmatrix, 3, 3, [])
%m(:, :, x) is matrix x
  2 件のコメント
MSP
MSP 2017 年 3 月 31 日
編集済み: MSP 2017 年 3 月 31 日
This does not print the right output.And moreover reshaping is cumbersome as the matrix may be not a x/x matrix rather x/y matrix and some of the matrix elements are needed to be truncated as well
Guillaume
Guillaume 2017 年 3 月 31 日
First answer should have been mat2cell not cell2mat. Fixed now.
This does not print the right output: then give, as text, not an image, so we can copy/paste into matlab, an example of input and desired output.
_ reshaping is cumbersome_. It's probably the easiest, and least cumbersome way to do what you want. Whether the matrix is square or not does not change anything. However, if some of the blocks needs to be bigger than others, then use mat2cell which is just as easy.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by