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

조회 수: 1 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by