How to create a new matrix with ascending values from another matrix

1 Ansicht (letzte 30 Tage)
i have this matrix
MT= [0.3540 50.4580
0.4380 33.4840
0.5220 21.8290
0.6060 15.6300
0.6900 12.4020
0.7580 10.5510
1.9400 15.5160
2.0090 21.8970
2.0930 31.6430
2.1780 40.9470
2.2630 48.9080
2.3480 56.8650
3.0250 45.4300
3.1080 26.6470
3.1750 15.1950
4.1880 10.8970
4.2730 20.7160
4.3580 31.3530
4.4250 39.0810
4.5110 47.8600
4.5950 56.0810
5.2720 45.8270
5.3560 24.2830
5.4390 10.8310
6.4360 14.4520
6.5210 23.6600
6.6060 34.1260
6.6910 43.0040
6.7750 51.6960
6.8430 56.2760]
i need to create a new matrix for each set of ascending numbers in the second column (with its corresponding value in the first column).
so in this case my matrix has 3 sets of values that met this criteria.
this means i should have 3 matrix as follows
M1=[0.7580 10.5510
1.9400 15.5160
2.0090 21.8970
2.0930 31.6430
2.1780 40.9470
2.2630 48.9080
2.3480 56.8650]
M2=[4.1880 10.8970
4.2730 20.7160
4.3580 31.3530
4.4250 39.0810
4.5110 47.8600
4.5950 56.0810]
M3=[5.4390 10.8310
6.4360 14.4520
6.5210 23.6600
6.6060 34.1260
6.6910 43.0040
6.7750 51.6960
6.8430 56.2760]
Any ideas? Thanks

Akzeptierte Antwort

Star Strider
Star Strider am 27 Aug. 2014
There are probably more efficient (and more generalized) ways to do it, but this works:
D2 = diff([Inf; MT(:,2)]);
GT = find(D2 > 0);
DGT = diff(GT);
GTI = find(DGT > 1);
M1 = MT(GT(1)-1:GT(GTI(1)),:);
M2 = MT(GT(GTI(1)+1)-1:GT(GTI(2)),:);
M3 = MT(GT(GTI(2)+1)-1:size(MT,1),:);
Rather than name them M1 ... M3, I would use a loop and create a cell array of them, such as M{1}...M{3}. If you had multiple centre segments (your M2 matrix here), that would be the way to go. The M{1} and M{3} elements would have to be essentially as they are here.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing 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!

Translated by