How to find the indices within blocks and sort the blocks thereafter?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Xiaohan Du
am 18 Jun. 2018
Beantwortet: Prajit T R
am 21 Jun. 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 Kommentar
Bob Thompson
am 18 Jun. 2018
What is the logic behind the block creation? Will they always be the same (four quadrants)?
Akzeptierte Antwort
Prajit T R
am 21 Jun. 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
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!