Student Support Forum: 'Recursive functions / Modules' topicStudent Support Forum > General > Archives > "Recursive functions / Modules"

 Next Comment > Help | Reply To Topic
 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: ,

 Subject (listing for 'Recursive functions / Modules') Author Date Posted Recursive functions / Modules Maxim 02/19/09 08:20am Re: Recursive functions / Modules Xavier 02/24/09 12:27pm Re: Re: Recursive functions / Modules Maxim 03/02/09 2:32pm Re: Recursive functions / Modules yehuda ben-s... 02/28/09 6:21pm Re: Re: Recursive functions / Modules Maxim 03/02/09 2:02pm
 Next Comment > Help | Reply To Topic