Creating a meshgrid of nodes
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexios Ioannidis
am 18 Sep. 2016
Kommentiert: Walter Roberson
am 19 Sep. 2016
Hello everyone, i would like to create a meshgrid in x-y axis, lets say for example a 9x9 grid. now i want to give values to each of the 81 nodes created in order to connect one node to the adjacent one that has the biggest value and so on unti i reach a final node..
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 19 Sep. 2016
That algorithm will get caught at every local maximum. For example, let the weights be
1 2 3 5
6 20 7 8
9 10 11 4
and let the final node be the position where the 4 is (bottom right.) If you start from the 1, 2, 3, 6, 7, 9, 10, or 11, they all lead to the 20 because it is larger than any of them. But once you are at the 20, there is no-where to go because there is no value greater than the 20 to step to. If you started at the 5, you would go to the 8, and from there you would go to the 11, and from there you would go to the 20, but starting from the 5 you could not get to the 4; similarly if you start from the 8 or 11 you cannot get to the 4. Because the 4 is not greater than the values around it, the only way you can get to the 4 with your algorithm is if you start at the 4.
2 Kommentare
Walter Roberson
am 19 Sep. 2016
Suppose you start at the node marked 1, target the node marked 4, and the rule is that you go to the highest-valued directly-adjacent node that you have not already visited. Then you would go 1 -> 20 -> 11 -> 10 -> 9 -> 6 -> 2 -> 7 -> 8 -> 5 -> 3 and then you are stuck because you have already visited all the neighbors of 3.
"My main problem is if there is a way to have a diagram of the nodes and the route from a starting to a final node."
directed graph. You would only create the directed edges that you traversed.
That is not the real difficulty. The real difficulty is that your algorithm gets stuck. This is a classic problem with locally- greedy algorithms.
Weitere Antworten (1)
KSSV
am 19 Sep. 2016
Bearbeitet: KSSV
am 19 Sep. 2016
Making mesh grid is straight forward in MATLAB. YOu have to give initial and final points with the number of points you want in between.
Eg:
P0 = [0 0] ; % initial point
P1 = [1 1] ; % final point
N = 9 ; % Number of points
x = linspace(0,1,N) ;
y = linspace(0,1,N) ;
[X,Y] = meshgrid(x,y) ;
If you want to assign a value to each node; define a 9x9 matrix..the respective indices (i,j) represent the value of (i,j)th node in X and Y.
Eg:
K = rand(9,9) ; % random data
surf(X,Y,K) ;
Siehe auch
Kategorien
Mehr zu Performance and Memory 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!