MRT function [1] "error code = 0" - multivariate-testing

When I make my MRT, I got two errors:
[1] "error code = 0" and Error in indval.default(Ynode, clustering =
clustnode, numitr = 1000) : All species must occur in at least one
plot. Does anyone have an idea of why? I checked and all my species
have an abundance >0...
MRTtest=mvpart(vegetation~ Placette+ Tourb + Transect + Largcanal + Annouvert + Elevation + Profnappe + Litiere+ Solnu+ Deblign+ Densiometre+ EpaissMO+ Vonpostvingt+ Vonpostsoixante+ Pyrovingt+ Pyrosoixante+ Sommesurfterr,tot,margin=0.08,cp=0,xv="pick",xval=10,xvmult=150,which=4,pca=F)
X-Val rep : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
106 107 108 109 110 111 112 113 114 115 116 117 118 119
120 121 122 123 124 125 126 127 128 129 130 131 132 133
134 135 136 137 138 139 140 141 142 143 144 145 146 147
148 149 150
Minimum tree sizes
tabmins
2 3 4 6
2 125 5 18
MRTtest1=MRT(MRTtest,percent=10,species=colnames(vegetation))
summary(MRTtest1)
Portion (%) of deviance explained by species for every particular node
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- Node 1 ---
Complexity(R2) 14.87422
Sommesurfterr>=6.024 Sommesurfterr< 6.024
~ Discriminant species :
THOnmtot THOmtot
% of expl. deviance 17.61057298 38.419650816
Mean on the left 0.37621604 0.430818462
Mean on the right 0.08877576 0.006259911
[1] "error code = 0"
~ INDVAL species for this node: : left is 1, right is 2
cluster indicator_value probability
THOmtot 1 0.9597 0.001
THOnmtot 1 0.7878 0.001
LEG 1 0.5802 0.031
LIB 1 0.5078 0.010
MELnmtot 1 0.4710 0.047
EPNnmtot 1 0.4404 0.026
Sum of probabilities = 87.497
Sum of Indicator Values = 30.02
Sum of Significant Indicator Values = 12.67
Number of Significant Indicators = 29
Significant Indicator Distribution
1 2
8 21
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- Node 2 ---
Complexity(R2) 7.920283
Densiometre< 19.88 Densiometre>=19.88
~ Discriminant species :
TRA THOmtot
% of expl. deviance 10.54536819 27.8848051
Mean on the left 0.02754503 0.5158733
Mean on the right 0.20823621 0.2220475
Error in indval.default(Ynode, clustering = clustnode, numitr = 1000)
: All species must occur in at least one plot

Related

How to sum columns of a matrix for a specified number of columns?

I have a matrix A of size 2500 x 500. I want to sum each 10 columns and get the result as a matrix B of size 2500 x 50. That is, the first column of B is the sum of the first 10 columns of A, the second column of B is the sum of second 10 columns of A, and so on.
How can I do that without a for loop? Since I have to do that hundreds of times and it is highly time consuming to do that using for loop.
First, we "block reshape" A, such that we have the desired number of columns. Therefore, we shamelessly steal the code from the great Divakar, and put in some minimal effort to generalize it. Then, we just need to sum along the second axis, and reshape to the original form.
Here's an example with five columns to be summed:
% Sample input data
A = reshape(1:100, 10, 10).'
[r, c] = size(A);
% Number of columns to be summed
n_cols = 5;
% Block reshape to n_cols, see https://stackoverflow.com/a/40508999/11089932
B = reshape(permute(reshape(A, r, n_cols, []), [1, 3, 2]), [], n_cols);
% Sum along second axis
B = sum(B, 2);
% Reshape to original form
B = reshape(B, r, c / n_cols)
That's the output:
A =
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
B =
15 40
65 90
115 140
165 190
215 240
265 290
315 340
365 390
415 440
465 490
Hope that helps!
This can be done with splitapply. An advantage of this approach is that it works even if the group size does not divide the number of columns (the last group is smaller):
A = reshape(1:120, 12, 10).'; % example 10×12 data (borrowed from HansHirse)
n_cols = 5; % number of columns to sum over
result = splitapply(#(x)sum(x,2), A, ceil((1:size(A,2))/n_cols));
In this example,
A =
1 2 3 4 5 6 7 8 9 10 11 12
13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48
49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72
73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96
97 98 99 100 101 102 103 104 105 106 107 108
109 110 111 112 113 114 115 116 117 118 119 120
result =
15 40 23
75 100 47
135 160 71
195 220 95
255 280 119
315 340 143
375 400 167
435 460 191
495 520 215
555 580 239

range of number to subset slices

I would like to reshape a vector into a number 'slices' (in Matlab) but find myself in a brain freeze and can't come up with a good way (e.g. a one-liner) to do it:
a=1:119;
slices=[47 24 1 47];
result={1:47,48:71,...};
the result doesn't need to be stored in a cell array.
Thanks
This is what mat2cell does:
>> a=1:119;
>> slices=[47 24 1 47];
>> result = mat2cell(a, 1, slices) % 1 is # of rows in result
result =
{
[1,1] =
Columns 1 through 15:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Columns 16 through 30:
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Columns 31 through 45:
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
Columns 46 and 47:
46 47
[1,2] =
Columns 1 through 15:
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
Columns 16 through 24:
63 64 65 66 67 68 69 70 71
[1,3] = 72
[1,4] =
Columns 1 through 13:
73 74 75 76 77 78 79 80 81 82 83 84 85
Columns 14 through 26:
86 87 88 89 90 91 92 93 94 95 96 97 98
Columns 27 through 39:
99 100 101 102 103 104 105 106 107 108 109 110 111
Columns 40 through 47:
112 113 114 115 116 117 118 119
}

How to reshape a matrix horizontally using MATLAB

I have matrix A of the size(4,192). It consists of 12 matrices of the size(4,4) aligned horizontally. I want to get matrix B with the size(12,16). B must get as follows:
suppose
A=[y1,y2,y3,...,y12]
in which yn is a 4*4 matrix. Then,
B=[y1,y4,y7,y10;
y2,y5,y8,y11;
y3,y6,y9,y12]
Is there an efficient/quicker (using no loop) way to do this using MATLAB?
You can try the following code:
ys1 = 2; % size(1) from submatrix (for the following example, use ys1 = 4 for the actual problem)
ys2 = 2; % size(2) from submatrix (for the following example, use ys2 = 4 for the actual problem)
ns1 = 3; % size(1) of final matrix in terms of submatrix (3 rows)
ns2 = 4; % size(2) of final matrix in terms of submatrix (4 columns)
temp = reshape(A,ys1,ys2,ns1,ns2);
B = reshape(permute(temp,[1 3 2 4]),ys1*ns1,ys2*ns2);
Example:
A = [11 12 21 22 31 32 41 42 51 52 61 62 71 72 81 82 91 92 101 102 111 112 121 122;
13 14 23 24 33 34 43 44 53 54 63 64 73 74 83 84 93 94 103 104 113 114 123 124];
B =
11 12 41 42 71 72 101 102
13 14 43 44 73 74 103 104
21 22 51 52 81 82 111 112
23 24 53 54 83 84 113 114
31 32 61 62 91 92 121 122
33 34 63 64 93 94 123 124

Comparing area between two matrices with multiple points of intersection (MATLAB)

I have two matrices that contain the points for the top boundaries of two jigsaw puzzles. I am trying to calculate the area contained between these two matrices (of unequal rows). They have multiple points of intersection. The picture below gives a better idea of what I'm trying to accomplish. The output should be a numerical value (of the total area highlighted in blue). If this is too difficult to achieve, is there a better way to compare matrices to see which ones "fit" the best?
Un-Highlighted Picture
Area(in blue) that I am trying to calculate (numerical value)
The matrix values are below if it helps:
Matrix 1:
1 1
2 2
3 2
4 2
5 2
6 3
7 3
8 3
9 3
10 3
11 3
12 2
13 2
14 2
15 2
16 2
17 2
18 2
19 2
20 2
21 2
22 2
23 2
24 2
25 2
26 2
27 2
28 2
29 2
30 2
31 2
32 2
33 2
34 2
35 2
36 2
37 2
38 2
39 2
40 2
41 2
42 2
43 2
44 2
45 2
46 2
47 2
48 2
49 2
50 2
51 2
52 2
53 2
54 2
55 2
56 2
57 2
58 2
59 2
60 2
61 2
62 2
63 2
64 2
65 2
66 2
67 2
68 2
69 2
70 2
71 2
72 3
73 3
74 3
75 4
76 5
77 6
78 7
79 8
79 9
80 10
80 11
80 12
80 13
80 14
80 15
79 16
79 17
79 18
78 19
78 20
78 21
77 22
77 23
77 24
76 25
76 26
76 27
75 28
75 29
75 30
74 31
74 32
74 33
73 34
73 35
73 36
73 37
73 38
72 39
72 40
72 41
72 42
72 43
72 44
73 45
73 46
73 47
74 48
75 49
76 50
77 51
78 52
79 53
80 53
81 54
82 54
83 55
84 55
85 56
86 56
87 57
88 57
89 57
90 58
91 58
92 58
93 58
94 59
95 59
96 59
97 59
98 59
99 59
100 59
101 59
102 59
103 59
104 59
105 59
106 59
107 59
108 59
109 59
110 59
111 59
112 58
113 58
114 58
115 58
116 57
117 57
118 57
119 56
120 56
121 56
122 55
123 55
124 54
125 53
126 53
127 52
128 51
129 51
130 50
131 49
132 48
132 47
133 46
133 45
133 44
133 43
133 42
133 41
133 40
133 39
133 38
132 37
132 36
132 35
131 34
131 33
131 32
131 31
130 30
130 29
130 28
130 27
129 26
129 25
128 24
128 23
127 22
127 21
127 20
127 19
126 18
126 17
126 16
126 15
126 14
126 13
126 12
126 11
126 10
126 9
127 8
128 7
129 6
130 5
131 4
132 3
133 3
134 2
135 2
136 2
137 2
138 2
139 2
140 2
141 2
142 2
143 2
144 2
145 2
146 2
147 2
148 2
149 2
150 2
151 2
152 2
153 2
154 2
155 2
156 2
157 2
158 2
159 2
160 2
161 2
162 2
163 2
164 2
165 2
166 2
167 2
168 1
169 1
170 1
171 1
172 1
Matrix 2:
173 3
172 3
171 3
170 2
169 2
168 2
167 2
166 2
165 2
164 2
163 2
162 2
161 2
160 2
159 2
158 2
157 2
156 2
155 2
154 2
153 2
152 2
151 2
150 2
149 2
148 2
147 2
146 2
145 2
144 2
143 2
142 2
141 2
140 2
139 2
138 2
137 2
136 2
135 3
134 3
133 3
132 3
131 4
130 4
129 4
128 5
127 6
127 7
127 8
126 9
127 10
127 11
127 12
127 13
127 14
126 15
127 16
127 17
127 18
127 19
127 20
127 21
128 22
128 23
128 24
128 25
129 26
129 27
129 28
130 29
130 30
130 31
131 32
131 33
131 34
132 35
132 36
132 37
132 38
133 39
133 40
133 41
133 42
133 43
132 44
132 45
132 46
131 47
130 48
129 49
128 50
127 51
126 52
125 53
124 54
123 54
122 55
121 55
120 55
119 56
118 56
117 57
116 58
115 58
114 59
113 59
112 59
111 59
110 60
109 60
108 60
107 60
106 60
105 60
104 60
103 60
102 60
101 60
100 60
99 60
98 60
97 60
96 60
95 59
94 59
93 59
92 59
91 59
90 58
89 58
88 57
87 57
86 56
85 56
84 55
83 55
82 54
81 54
80 53
79 52
78 51
77 50
76 49
75 48
74 47
73 46
73 45
73 44
73 43
73 42
73 41
73 40
73 39
73 38
73 37
73 36
74 35
74 34
74 33
75 32
75 31
75 30
76 29
76 28
76 27
77 26
77 25
77 24
78 23
78 22
78 21
79 20
79 19
80 18
80 17
80 16
81 15
81 14
81 13
81 12
81 11
81 10
80 10
79 9
79 8
78 7
77 6
76 5
75 4
74 4
73 3
72 3
71 2
70 2
69 2
68 1
67 2
66 2
65 2
64 2
63 2
62 2
61 2
60 2
59 2
58 2
57 2
56 2
55 2
54 2
53 2
52 2
51 2
50 2
49 2
48 2
47 2
46 2
45 2
44 2
43 2
42 2
41 2
40 2
39 2
38 2
37 2
36 2
35 2
34 2
33 2
32 2
31 2
30 2
29 2
28 2
27 2
26 2
25 2
24 2
23 2
22 2
21 2
20 2
19 2
18 2
17 2
16 2
15 2
14 2
13 2
12 2
11 2
10 2
9 2
8 2
7 2
6 2
5 2
4 2
3 2
2 2
1 3
Mark everything above one curve and mark everything below the other curve. Then you can get the area between the curves by finding where there are two marks.
You should take a look at this question Similarity measures between curves?

How can I retrieve the coordinate from excel and plot the points according to the map? - MATLAB

I'm currently working on map routing system for pedestrian pathway and not sure does anyone did this before. But I have collected various way-points coordinates of the path using google earth.
Below data are the coordinates points for the pathway which is save it on Excel and import to Matlab
1 1.37723400000000 103.839645000000
2 1.37722000000000 103.839741000000
3 1.37723300000000 103.839843000000
4 1.37723600000000 103.839968000000
5 1.37724100000000 103.840125000000
6 1.37723900000000 103.840245000000
7 1.37724900000000 103.840435000000
8 1.37725700000000 103.840674000000
9 1.37724800000000 103.840896000000
10 1.37726500000000 103.841071000000
11 1.37728300000000 103.841190000000
12 1.37729500000000 103.841393000000
13 1.37734600000000 103.841591000000
14 1.37736500000000 103.841918000000
15 1.37739800000000 103.842093000000
16 1.37742900000000 103.842400000000
17 1.37744900000000 103.842629000000
18 1.37748100000000 103.842895000000
19 1.37750200000000 103.843164000000
20 1.37752800000000 103.843428000000
21 1.37756500000000 103.843689000000
22 1.37757000000000 103.843997000000
23 1.37758500000000 103.844248000000
24 1.37749200000000 103.844499000000
25 1.37765800000000 103.844515000000
26 1.37806100000000 103.844467000000
27 1.37853700000000 103.844386000000
28 1.37888000000000 103.844349000000
29 1.37924600000000 103.844303000000
30 1.37957500000000 103.844266000000
31 1.37966200000000 103.844190000000
32 1.37965300000000 103.844034000000
33 1.37963800000000 103.843813000000
34 1.37961600000000 103.843550000000
35 1.37959500000000 103.843313000000
36 1.37957600000000 103.843097000000
37 1.37957300000000 103.843007000000
38 1.37956800000000 103.842852000000
39 1.37953900000000 103.842602000000
40 1.37949900000000 103.842315000000
41 1.37948700000000 103.842056000000
42 1.37953800000000 103.841882000000
43 1.37967800000000 103.841755000000
44 1.37984000000000 103.841674000000
45 1.38007300000000 103.841546000000
46 1.38027900000000 103.841430000000
47 1.38044400000000 103.841354000000
48 1.38064800000000 103.841248000000
49 1.38092400000000 103.841100000000
50 1.38125600000000 103.840942000000
51 1.38178300000000 103.840682000000
52 1.38202300000000 103.840565000000
53 1.38236700000000 103.840396000000
54 1.38271600000000 103.840206000000
55 1.38302800000000 103.840017000000
56 1.38314600000000 103.840222000000
57 1.38299000000000 103.840230000000
58 1.38286700000000 103.840288000000
59 1.38265300000000 103.840398000000
60 1.38242100000000 103.840522000000
61 1.38219900000000 103.840638000000
62 1.38195100000000 103.840766000000
63 1.38162100000000 103.840934000000
64 1.38130200000000 103.841093000000
65 1.38106700000000 103.841202000000
66 1.38088500000000 103.841286000000
67 1.38069300000000 103.841372000000
68 1.38049000000000 103.841494000000
69 1.38018700000000 103.841659000000
70 1.37988900000000 103.841822000000
71 1.37966700000000 103.841963000000
72 1.37965000000000 103.842037000000
73 1.37965100000000 103.842220000000
74 1.37966300000000 103.842363000000
75 1.37968900000000 103.842641000000
76 1.37973000000000 103.843049000000
77 1.37975300000000 103.843305000000
78 1.37978200000000 103.843690000000
79 1.37982300000000 103.844135000000
80 1.37989800000000 103.844222000000
81 1.37996400000000 103.844230000000
82 1.38029900000000 103.844183000000
83 1.38080600000000 103.844091000000
84 1.38119600000000 103.843985000000
85 1.38170500000000 103.843838000000
86 1.38194900000000 103.843765000000
87 1.38220500000000 103.843683000000
88 1.38250000000000 103.843564000000
89 1.38296800000000 103.843388000000
90 1.38367400000000 103.843107000000
91 1.38379700000000 103.842994000000
92 1.38384900000000 103.842791000000
93 1.38376700000000 103.842173000000
94 1.38372500000000 103.841758000000
95 1.38358400000000 103.841212000000
96 1.38350400000000 103.840867000000
97 1.38324600000000 103.840388000000
98 1.38288200000000 103.839785000000
99 1.38265700000000 103.839436000000
100 1.38238700000000 103.838973000000
101 1.38224900000000 103.838785000000
102 1.38215800000000 103.838830000000
103 1.38197900000000 103.838933000000
104 1.38162900000000 103.839097000000
105 1.38115400000000 103.839338000000
106 1.38080900000000 103.839609000000
107 1.38036600000000 103.839756000000
108 1.37995000000000 103.839782000000
109 1.37957400000000 103.839826000000
110 1.37904400000000 103.839883000000
111 1.37844300000000 103.839807000000
112 1.37803700000000 103.839743000000
113 1.37765800000000 103.839690000000
114 1.37735600000000 103.839665000000
115 1.38310100000000 103.840134000000
116 1.38108800000000 103.841146000000
117 1.37961700000000 103.842951000000
118 1.37978200000000 103.844233000000
My Code
M = xlsread('YCKMap.xlsx');
figure(),plot(M(:,2), M(:,3));
RESULT
http://i.stack.imgur.com/0dncY.jpg
What I want:
Is it possible to join these points together
(55 115 56) (49 116 65) (37 117 76) (30 118 80)
As shown in the image above?
I have figure out the answer for my question and would like to benefit the community for what I have come out with. According #Dan code plot(M(:,2), M(:,3); can plot the points out but the orientation of the graph is way off. Therefore I use waypoints function to make it better.
Anyway, organize your excel data by leaving a cell gap when you want to insert a new line.
I have paste the excel data for you to get a clearer picture.
Coding
M = xlsread('excel.xlsx');
waypoints =[M(:,2), M(:,3)];
[lttrk,lntrk] = track('rh',waypoints,'degrees');
figure(),geoshow(lttrk,lntrk,'DisplayType','line', 'color','r');
Excel Data
1 1.377234 103.839645
2 1.37722 103.839741
3 1.377233 103.839843
4 1.377236 103.839968
5 1.377241 103.840125
6 1.377239 103.840245
7 1.377249 103.840435
8 1.377257 103.840674
9 1.377248 103.840896
10 1.377265 103.841071
11 1.377283 103.84119
12 1.377295 103.841393
13 1.377346 103.841591
14 1.377365 103.841918
15 1.377398 103.842093
16 1.377429 103.8424
17 1.377449 103.842629
18 1.377481 103.842895
19 1.377502 103.843164
20 1.377528 103.843428
21 1.377565 103.843689
22 1.37757 103.843997
23 1.377585 103.844248
24 1.377492 103.844499
25 1.377658 103.844515
26 1.378061 103.844467
27 1.378537 103.844386
28 1.37888 103.844349
29 1.379246 103.844303
30 1.379575 103.844266
31 1.379662 103.84419
32 1.379653 103.844034
33 1.379638 103.843813
34 1.379616 103.84355
35 1.379595 103.843313
36 1.379576 103.843097
37 1.379573 103.843007
38 1.379568 103.842852
39 1.379539 103.842602
40 1.379499 103.842315
41 1.379487 103.842056
42 1.379538 103.841882
43 1.379678 103.841755
44 1.37984 103.841674
45 1.380073 103.841546
46 1.380279 103.84143
47 1.380444 103.841354
48 1.380648 103.841248
49 1.380924 103.8411
50 1.381256 103.840942
51 1.381783 103.840682
52 1.382023 103.840565
53 1.382367 103.840396
54 1.382716 103.840206
55 1.383028 103.840017
56 1.383146 103.840222
57 1.38299 103.84023
58 1.382867 103.840288
59 1.382653 103.840398
60 1.382421 103.840522
61 1.382199 103.840638
62 1.381951 103.840766
63 1.381621 103.840934
64 1.381302 103.841093
65 1.381067 103.841202
66 1.380885 103.841286
67 1.380693 103.841372
68 1.38049 103.841494
69 1.380187 103.841659
70 1.379889 103.841822
71 1.379667 103.841963
72 1.37965 103.842037
73 1.379651 103.84222
74 1.379663 103.842363
75 1.379689 103.842641
76 1.37973 103.843049
77 1.379753 103.843305
78 1.379782 103.84369
79 1.379823 103.844135
80 1.379898 103.844222
81 1.379964 103.84423
82 1.380299 103.844183
83 1.380806 103.844091
84 1.381196 103.843985
85 1.381705 103.843838
86 1.381949 103.843765
87 1.382205 103.843683
88 1.3825 103.843564
89 1.382968 103.843388
90 1.383674 103.843107
91 1.383797 103.842994
92 1.383849 103.842791
93 1.383767 103.842173
94 1.383725 103.841758
95 1.383584 103.841212
96 1.383504 103.840867
97 1.383246 103.840388
98 1.382882 103.839785
99 1.382657 103.839436
100 1.382387 103.838973
101 1.382249 103.838785
102 1.382158 103.83883
103 1.381979 103.838933
104 1.381629 103.839097
105 1.381154 103.839338
106 1.380809 103.839609
107 1.380366 103.839756
108 1.37995 103.839782
109 1.379574 103.839826
110 1.379044 103.839883
111 1.378443 103.839807
112 1.378037 103.839743
113 1.377658 103.83969
114 1.377356 103.839665
1 1.377234 103.839645
49 1.380924 103.8411
116 1.381088 103.841146
65 1.381067 103.841202
37 1.379573 103.843007
117 1.379617 103.842951
76 1.37973 103.843049
30 1.379575 103.844266
118 1.379782 103.844233
80 1.379898 103.844222
If you want to plot points in Matlab in a different order from that which they appear in your matrix, append a column vector at the beginning of the matrix that is a vector of the order the point should appear in. Then use the sortrows function of matlab to rearrange the matrix. It will now be in the correct order for plotting. For example:
M = [0 4 2; 1 17 5]';
plot(M);
Now suppose you knew that the correct plot order was (0,1) then (2,5) then (4,17). Compared to the input matrix, M, the correct plot order can be specified by order = [1 3 2]'
So to plot in the correct order:
M = [order'; M'];
M = sortrows(M);
plot(M(:,2), M(:,3);
Which means as long as you know the correct plot order, you can now use this method to get the correct plot.
So in your example you want those points to be plotted in this order (55 115 56) (49 116 65) (37 117 76) (30 118 80). Lets assume you want them to start at 55 as this is the first point in your new order, currently M looks like this: M = [...;30 118 80;...;37 117 76;...;49 116 65;...;55 115 56;...] but you want it to look like this: M = [...; 55 115 56; 56 116 65; 57 117 76; 58 118 80;...]. The problem is that you can't just change the values like this M(M(:,1) == 30,1) = 58 because then you will land up with 2 points indexed at 58. So first you need to add 1 too all the indices that are 58 or higher, so M(M(:,1) >= 58) = M(M(:,1) >= 58) + 1 and then finally M(M(:,1) == 30,1) = 58. So to generalise the changing of a point:
M(M(:,1) >= newIndex) = M(M(:,1) >= newIndex) + 1;
M(M(:,1) == oldIndex,1) = newIndex;
If there is some logic that define how you change the points, then you can write this into a loop. If not and it is just those 4 points, then just run this manually in the command line.