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

1 visualizzazione (ultimi 30 giorni)
Xiaohan Du il 18 Giu 2018
Risposto: Prajit T R il 21 Giu 2018
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 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Bob Thompson il 18 Giu 2018
What is the logic behind the block creation? Will they always be the same (four quadrants)?

Accedi per commentare.

### Risposta accettata

Prajit T R il 21 Giu 2018
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
Hope this helps
Prajit
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Matrix Indexing in Help Center e File Exchange

R2017b

### Community Treasure Hunt

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

Start Hunting!

Translated by