How to find the indices within blocks and sort the blocks thereafter?

2 ビュー (過去 30 日間)
Xiaohan Du
Xiaohan Du 2018 年 6 月 18 日
回答済み: Prajit T R 2018 年 6 月 21 日
Hi all,
Say I have the following matrix contains 15 elements:
M =
6 2 9
7 2 3
9 3 10
10 9 4
6 3 2
and the following coordinates which represent 4 blocks:
K>> block{:}
ans =
-1 -1
0 -1
0 0
-1 0
ans =
-1 0
0 0
0 1
-1 1
ans =
0 -1
1 -1
1 0
0 0
ans =
0 0
1 0
1 1
0 1
Now I'd like to separate the elements in M into 4 blocks using information in 'block' as the following picture:
So the result should be:
K>> mBlock{:}
ans =
6 2
7 2
9 3
ans =
2 9
2 3
3 10
ans =
9 3
10 9
6 3
ans =
3 10
9 4
3 2
How can I do it? Thanks a lot!
  1 件のコメント
Bob Thompson
Bob Thompson 2018 年 6 月 18 日
What is the logic behind the block creation? Will they always be the same (four quadrants)?

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

採用された回答

Prajit T R
Prajit T R 2018 年 6 月 21 日
Hi
Here's a code which will work for a size m x n matrix provided that m and n are odd values. To incorporate even values, you have to make some minor tweaks, that's all. You can divide a matrix into 4 quadrants as per your requirement using the following:
M =[6 2 9; 7 2 3; 9 3 10; 10 9 4; 6 3 2]; %The input matrix that needs to be divided
m=5; %number of rows
n=3; %number of coloumns
a=floor(m+1/2); %finding the midline of the rows
b=floor(n+1/2); %finding the midline of the coloumns
q1=M(1:a,1:b) %quadrant-1
q2=M(1:a,2:n) %quadrant-2
q3=M(a:m,1:b) %quadrant-3
q4=M(a:m,2:n) %quadrant-4
Hope this helps
Prajit

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by