Strange random-seed behaviour after create-<breeds>-with - netlogo
I am experiencing some strange random-seed behaviour in my model.
The following procedure:
to testRNG
clear-all
random-seed 10
type random 100
type ","
create-nodes 10
type random 100
type ","
ask nodes[ create-node2node-links-with other nodes in-radius (1000)]
print random 100
end
Produces output that looks like this:
observer> testRNG
78,78,42
observer> testRNG
78,78,42
observer> testRNG
78,78,40
observer> testRNG
78,78,42
observer> testRNG
78,78,71
observer> testRNG
78,78,52
observer> testRNG
78,78,71
observer> testRNG
78,78,40
observer> testRNG
78,78,97
observer> testRNG
78,78,52
observer> testRNG
78,78,97
observer> testRNG
78,78,52
observer> testRNG
78,78,18
observer> testRNG
78,78,19
observer> testRNG
78,78,27
observer> testRNG
78,78,34
observer> testRNG
78,78,58
observer> testRNG
78,78,52
observer> testRNG
78,78,40
Obviously something is happening when the breeded links are created, but I am really unsure what it is. For completeness note that node2node-links are undirected and declared as:
undirected-link-breed [node2node-links node2node-link]
Puzzlingly, while the third call to random 100 is clearly not reproducible, it also looks like it may not be pseudo-random.
I have investigated this a little further and something strange is clearly happening - here is a another example from my actual runtime code. In this case the links are created after the 5th call to random 100, subsequent calls are not reproducible - however I have to think that the odds of the RNG generating "34, 1, 1" seven times out of nineteen would be very small.
START 66 , 62 , 61 , 21 , 62 , 10 , 67 , 2 END
START 66 , 62 , 61 , 21 , 62 , 34 , 1 , 1 END
START 66 , 62 , 61 , 21 , 62 , 34 , 1 , 60 END
START 66 , 62 , 61 , 21 , 62 , 29 , 32 , 41 END
START 66 , 62 , 61 , 21 , 62 , 16 , 71 , 78 END
START 66 , 62 , 61 , 21 , 62 , 10 , 67 , 2 END
START 66 , 62 , 61 , 21 , 62 , 34 , 1 , 1 END
START 66 , 62 , 61 , 21 , 62 , 34 , 1 , 1 END
START 66 , 62 , 61 , 21 , 62 , 34 , 1 , 1 END
START 66 , 62 , 61 , 21 , 62 , 34 , 1 , 1 END
START 66 , 62 , 61 , 21 , 62 , 29 , 32 , 41 END
START 66 , 62 , 61 , 21 , 62 , 81 , 26 , 63 END
START 66 , 62 , 61 , 21 , 62 , 92 , 11 , 93 END
START 66 , 62 , 61 , 21 , 62 , 88 , 93 , 60 END
START 66 , 62 , 61 , 21 , 62 , 34 , 1 , 1 END
START 66 , 62 , 61 , 21 , 62 , 34 , 1 , 1 END
START 66 , 62 , 61 , 21 , 62 , 34 , 93 , 60 END
START 66 , 62 , 61 , 21 , 62 , 88 , 93 , 60 END
START 66 , 62 , 61 , 21 , 62 , 94 , 11 , 38 END
I have created a blank model with just the node and node2node breeds/link-breeds and this single procedure and the behaviour does not occur - instead all calls to random 100 are reproducible.
I am at pains to include all my model code as it is fairly long and would undoubtedly be information overload - moreover, by calling clear-all I think I can rule out dependancy on some other section of the program.
If anyone has any ideas on what might be happening here, or can highlight something simple I have overlooked, it would be greatly appreciated.
Summary from comments:
This is due to a bug in the NW extension where running nw:weak-component-clusters in a monitor was sporadically advancing the main random number generator. Monitors and plots are meant to use their own RNG, so any code you run in a monitor or plot should not affect the outcome of other code.
https://github.com/NetLogo/NW-Extension/issues/144
Related
patches-own a vector in netlogo
In the patches-own section at the start, can I index one of the variables over a breed, so it's a vector rather than a single variable? Specifically, I've got a breed called Developers (it's an ABM of house-building), and patches own a land-price, but I want them to own a different land price for each developer. Is this possible? My failed attempt, with 2 developers, is patches-own [ land-price ( n-values 2 developer ) ] Thanks.
This can be solved a numerous ways. One solution can be to let the patch-variable be a list. You can't initialize it inside the patches-own block. Instead, initialize it in your setup method. patches-own [land-prices] to setup ca create-developers 10 let initial-price 10 ask patches [ set land-prices (count developers) initial-price] end You'll need to be careful about ordering though. For example, alot of the commands like of produces a list of random size. You may want to use the developer's who to index them. One way to get around that is to use the table extension to create a table of who to price. You'd need to include table in your extensions and modify your setup. See: https://ccl.northwestern.edu/netlogo/docs/table.html Consider this for the table solution, where I make use of the from-list function in tables to initialize the table: patches-own [land-prices] breed [developers developer] extensions [table] to setup ca create-developers 10 let initial-price 10 ask patches [ set land-prices table:from-list [(list who initial-price)] of developers] end Both of these are memory intensive operations. You may want to tread lightly or explain why it's necessary to store so much information.
#mattsap's suggestion of using the table extension is probably the way to go, but just for the record: you might also consider using links. The problem, in this case, is that a link can only be between a turtle and a turtle, never between turtle and a patch. You could, however, consider making your "lands" turtles, and just put one on each patch. Here is a full example of what I mean: breed [ lands land ] breed [ developers developer ] undirected-link-breed [ price-links price-link ] price-links-own [ price ] to setup clear-all set-default-shape lands "square" create-developers 10 ask patches [ sprout-lands 1 [ set color green - 3 create-price-links-with n-of 2 developers [ hide-link set price random 100 ] ] ] end Depending on what you're trying to do, there might be some trade offs involved (memory being one) but conceptually, this is a very clean way to proceed. And NetLogo makes it very easy and pleasant to work with links (much more pleasant than using the table extension in my opinion). The main advantage is that you can query links from both directions: observer> ask one-of developers [ show [ price ] of my-price-links ] (developer 6): [85 68 79 26 40 60 72 85 94 50 63 75 81 97 15 46 71 34 75 15 87 0 30 9 57 23 14 63 73 66 5 13 94 20 78 8 36 12 18 49 43 35 24 38 93 34 15 72 63 68 15 86 46 21 30 67 19 89 73 62 83 33 14 13 62 46 54 17 12 35 58 7 29 51 35 99 95 96 78 74 81 36 98 45 86 2 3 45 24 35 35 43 11 63 72 11 50 16 14 60 36 89 83 50 64 65 11 38 92 75 78 94 76 12 77 30 6 61 79 63 39 68 20 99 43 72 74 1 12 18 70 98 23 72 2 15 11 44 29 17 24 73 74 53 42 63 23 53 86 45 6 60 17 49 98 79 69 96 54 6 19 20 99 46 1 31 66 85 22 42 74 2 19 60 93 54 37 20 77 75 64 42 78 40 82 11 91 13 56 56 28 34 42 5 75 7 46 91 69 83 76 92 69 71 14 35 30 85 78 95 25 3 2 1 77 73 92 31 54 83 5 89 2 32 19 10 59 72 80 93 60 62 44 92 49 49] observer> ask one-of lands [ show [ price ] of my-price-links ] (land 997): [43 70] Or you can get to the developers directly from the land (and vice versa): observer> ask one-of lands [ show sort price-link-neighbors ] (land 112): [(developer 4) (developer 5)] To show the price of a specific developer for a specific land: observer> ask developer 2 [ show [ price ] of price-link-with land 737 ] (developer 2): 94 See the Links section of the NetLogo dictionnary for all the neat things that you can do...
How to check 4 neighbor connectivity in grayscale image
mat = 147 155 139 104 84 139 136 134 99 73 60 144 98 82 60 54 47 118 86 59 46 48 38 90 88 66 50 44 35 67 88 75 53 40 43 48 p = mat(3,3) q = mat(2,5) V = [1:60] all i want is to check if there exist a path between pixel p and q using vector V, for example given matrix above there exist a paths: path1: (3,3) , (3,4) , (3,5) , (2,5) path2: (3,3) , (4,3) , (4,4) , (4,5) , (3,5) , (2,5) and many other paths, Note: pixel value in each path's coordinate should be in 'V' and obviously p and q should also be in 'V'. that's what i am trying to achieve in MATLAB Code i've written so far: mat = 147 155 139 104 84 139 136 134 99 73 60 144 98 82 60 54 47 118 86 59 46 48 38 90 88 66 50 44 35 67 88 75 53 40 43 48 p = mat(3,3) q = mat(2,5) V = [1:60] % need to check N4 connectivity through pixel value p to q cc = bwconncomp(mat,4) for i=1:cc.NumObjects pix = cc.PixelIdxList{i} if any(ismember(pix(:), p)) && any(ismember(pix(:), q)) && any(ismember(V(:), p)) && any(ismember(V(:), q)) display('found N4 connectivity') end Actual Question: is this correct way to do the required task or am i doing it wrong?
MRT function [1] "error code = 0"
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
Matlab: select submatrix from matrix by certain criteria
I have a matrix A A=[f magic(10)] A= 931142103 92 99 1 8 15 67 74 51 58 40 931142103 98 80 7 14 16 73 55 57 64 41 931142103 4 81 88 20 22 54 56 63 70 47 459200101 85 87 19 21 3 60 62 69 71 28 459200101 86 93 25 2 9 61 68 75 52 34 459200101 17 24 76 83 90 42 49 26 33 65 459200101 23 5 82 89 91 48 30 32 39 66 37833100 79 6 13 95 97 29 31 38 45 72 37833100 10 12 94 96 78 35 37 44 46 53 37833100 11 18 100 77 84 36 43 50 27 59 The first column are firm codes. The rest columns are firms' data, with each row referring to the firm in Column 1 in a given year. Notice that years may not be balance for every firms. I would like to subtract sub-matrices according to the first column. For instance, for A(1:3,2:11) for 931142103: A(1:3,2:11) ans = 92 99 1 8 15 67 74 51 58 40 98 80 7 14 16 73 55 57 64 41 4 81 88 20 22 54 56 63 70 47 Same as 459200101 (which would be A(4:7,2:11)) and A(8:10,2:11) for 37833100. I get a sense that the code should like this: indices=find(A(:,1)); obs=size(A(:,1)); for i=1:obs, if i==indices(i ??) A{i}=A(??,2:11); end end I have difficulties in indexing these complicated codes: 459200101 and 37833100 in order to gather them together. And how can I write the rows of my submatrix A{i}? Thanks so much!
One approach with arrayfun - %// Get unique entries from first column of A and keep the order %// with 'stable' option i.e. don't sort unqA1 = unique(A(:,1),'stable') %// Use arrayfun to select each such submatrix and store as a cell %// in a cell array, which is the final output outA = arrayfun(#(n) A(A(:,1)==unqA1(n),:),1:numel(unqA1),'Uni',0) Or this - [~,~,row_idx] = unique(A(:,1),'stable') outA = arrayfun(#(n) A(row_idx==n,:),1:max(row_idx),'Uni',0) Finally, you can verify results with a call to celldisp(outA)
If values in column 1 always appear grouped (as in your example), you can use mat2cell as follows: result = mat2cell(A, diff([0; find(diff(A(:,1))); size(A,1)])); If they don't, just sort the rows of A according to column 1 before applying the above: A = sortrows(A,1); result = mat2cell(A, diff([0; find(diff(A(:,1))); size(A,1)]));
If you don't mind the results internally not being ordered, you can use accumarray for this: [~,~,I] = unique(A(:,1),'stable'); partitions = accumarray(I, 1:size(A,1), [], #(I){A(I,2:end)});
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.