Mercurial > hg > octave-lyh
diff scripts/sparse/treeplot.m @ 10549:95c3e38098bf
Untabify .m scripts
author | Rik <code@nomad.inbox5.com> |
---|---|
date | Fri, 23 Apr 2010 11:28:50 -0700 |
parents | 1bf0ce0930be |
children | be55736a0783 |
line wrap: on
line diff
--- a/scripts/sparse/treeplot.m +++ b/scripts/sparse/treeplot.m @@ -41,13 +41,13 @@ if (nargin > 2) edge_style = edge_s; if (nargin > 1) - if (length (findstr (node_s, "*")) == 0 - && length (findstr (node_s, "+")) == 0 - && length (findstr (node_s, "x")) == 0) - node_style = [node_s, "o"]; - else - node_style = node_s; - endif + if (length (findstr (node_s, "*")) == 0 + && length (findstr (node_s, "+")) == 0 + && length (findstr (node_s, "x")) == 0) + node_style = [node_s, "o"]; + else + node_style = node_s; + endif endif endif @@ -72,13 +72,13 @@ stop = zeros (1, num_nodes+1); for i = 1:num_nodes+1 start(i) = pos; - xhelp(i) = pos; - pos += num_children(i); - stop(i) = pos; + xhelp(i) = pos; + pos += num_children(i); + stop(i) = pos; endfor for i = 1:num_nodes vec_of_child(xhelp(tree(i)+1)) = i; - xhelp(tree(i)+1) = xhelp(tree(i)+1)+1; + xhelp(tree(i)+1) = xhelp(tree(i)+1)+1; endfor ## The number of "parent" (actual) node (it's descendants will be @@ -106,57 +106,57 @@ ## The top of the stack. while (par_number != -1) - if (start(par_number+1) < stop(par_number+1)) - idx = vec_of_child(start(par_number+1):stop(par_number+1)-1); - else - idx = zeros (1, 0); - endif + if (start(par_number+1) < stop(par_number+1)) + idx = vec_of_child(start(par_number+1):stop(par_number+1)-1); + else + idx = zeros (1, 0); + endif ## Add to idx the vector of parent descendants. - stk = [stk; [idx', ones(fliplr(size(idx)))*par_number]]; - ## Add to stack the records relevant to parent descandant s. - if (par_number != 0) - skelet = [skelet; ([ones(size(idx))*par_number; idx])(:)]; - endif + stk = [stk; [idx', ones(fliplr(size(idx)))*par_number]]; + ## Add to stack the records relevant to parent descandant s. + if (par_number != 0) + skelet = [skelet; ([ones(size(idx))*par_number; idx])(:)]; + endif - ## If there is not any descendant of "parent node": - if (stk(end,2) != par_number) - left_most++; + ## If there is not any descendant of "parent node": + if (stk(end,2) != par_number) + left_most++; x_coordinate_r(par_number) = left_most; - max_ht = min (max_ht, level); + max_ht = min (max_ht, level); if (length(stk) > 1 && find ((shift(stk,1)-stk) == 0) > 1 - && stk(end,2) != stk(end-1,2)) - ## Return to the nearest branching the position to return - ## position is the position on the stack, where should be - ## started further search (there are two nodes which has the - ## same parent node). + && stk(end,2) != stk(end-1,2)) + ## Return to the nearest branching the position to return + ## position is the position on the stack, where should be + ## started further search (there are two nodes which has the + ## same parent node). position = (find ((shift(stk(:,2),1)-stk(:,2)) == 0))(end) + 1; par_number_vec = stk(position:end,2); ## The vector of removed nodes (the content of stack form - ## position to end). + ## position to end). skelet = [skelet; flipud(par_number_vec)]; level += length (par_number_vec); - ## The level have to be decreased. + ## The level have to be decreased. x_coordinate_r(par_number_vec) = left_most; stk(position:end,:) = []; - endif - ## Remove the next node from "searched branch". - stk(end,:) = []; - ## Choose new "parent node". + endif + ## Remove the next node from "searched branch". + stk(end,:) = []; + ## Choose new "parent node". par_number = stk(end,1); - ## If there is another branch start to search it. - if (par_number != -1) - skelet = [skelet; stk(end,2); par_number]; - y_coordinate(par_number) = level; - x_coordinate_l(par_number) = left_most + 1; - endif - else + ## If there is another branch start to search it. + if (par_number != -1) + skelet = [skelet; stk(end,2); par_number]; + y_coordinate(par_number) = level; + x_coordinate_l(par_number) = left_most + 1; + endif + else ## There were descendants of "parent nod" choose the last of - ## them and go on through it. + ## them and go on through it. level--; - par_number = stk(end,1); - y_coordinate(par_number) = level; - x_coordinate_l(par_number) = left_most + 1; - endif + par_number = stk(end,1); + y_coordinate(par_number) = level; + x_coordinate_l(par_number) = left_most + 1; + endif endwhile ## Calculate the x coordinates (the known values are the position @@ -169,37 +169,37 @@ hold_is_on = ishold (); unwind_protect - hold ("on"); + hold ("on"); - ## Plot grah nodes. - plot (x_coordinate, y_coordinate, node_style); + ## Plot grah nodes. + plot (x_coordinate, y_coordinate, node_style); - ## Helping command - usable for plotting edges - skelet = [skelet; 0]; + ## Helping command - usable for plotting edges + skelet = [skelet; 0]; - ## Draw graph edges. - idx = find (skelet == 0); + ## Draw graph edges. + idx = find (skelet == 0); - ## Plot each tree component in one loop. - for i = 2:length(idx) - ## Tree component start. - istart = idx(i-1) + 1; - ## Tree component end. - istop = idx(i) - 1; - if (istop - istart < 1) - continue; - endif - plot (x_coordinate(skelet(istart:istop)), - y_coordinate(skelet(istart:istop)), edge_style) - endfor + ## Plot each tree component in one loop. + for i = 2:length(idx) + ## Tree component start. + istart = idx(i-1) + 1; + ## Tree component end. + istop = idx(i) - 1; + if (istop - istart < 1) + continue; + endif + plot (x_coordinate(skelet(istart:istop)), + y_coordinate(skelet(istart:istop)), edge_style) + endfor - ## Set axis and graph size. - axis ([0.5, left_most+0.5, max_ht-0.5, num_nodes-0.5], "nolabel"); + ## Set axis and graph size. + axis ([0.5, left_most+0.5, max_ht-0.5, num_nodes-0.5], "nolabel"); unwind_protect_cleanup - if (! hold_is_on) - hold ("off"); - endif + if (! hold_is_on) + hold ("off"); + endif end_unwind_protect endif