| Author |
Comment/Response |
Maxim
|
02/19/09 08:20am
I'm a little stuck with recursive function getCl[x_,y_], that is being called from getClusters[binDat_] function.
it has localCluster that needs to be visible at all times for getCl[].
Everything works if I do not put getCl[] inside getClusters[], but when it is in the module errors pop out.
binaryData={{0,0,1,0},{0,0,1,0},{0,1,1,0},{0,0,0,0}};
localCluster = {};
getCl[x_, y_] := Module[{},
If[x <= 0 || y <= 0 || x > Dimensions[binData][[1]] ||
y > Dimensions[binData][[2]], ,
If[binDat[[x, y]] == 1 && check[[x, y]] != 1,
check[[x, y]] = 1;
AppendTo[localCluster, {x, y}];
getCl[x + 1, y];
getCl[x - 1, y];
getCl[x, y + 1];
getCl[x, y - 1];
]
]
]
$RecursionLimit = Infinity;
getClusters[binDat_] := Module[{binData = binDat},
check =
Table[0, {Dimensions[binData][[1]]}, {Dimensions[binData][[
2]]}];(*Add 3rd dimention for clustering algorithm*)
clusters = {};
For [i = 1, i <= rows,
For[j = 1, j <= columns,
getCl[i, j];
If[Length[localCluster] > 0, AppendTo[clusters, localCluster]];
localCluster = {};
j++;];
i++];
clusters
];
myclusters = getClusters[binaryData];
URL: , |
|