gistlib
Here's a sample code to create a Christmas tree graph in MATLAB:
main.m% Define tree parameters levels = 10; width = 40; % Initialize matrix tree = repmat(' ', levels, width); % Add branches to tree for i = 1:levels start = width/2 - (i-1); stop = width/2 + (i-1); branches = start:stop; tree(i, branches) = '#'; end % Add trunk to tree trunk_start = floor(width/2) - 2; trunk_stop = floor(width/2) + 2; trunk = levels:levels+3; tree(trunk, trunk_start:trunk_stop) = '|'; % Display tree disp(tree) 447 chars24 lines
% Define tree parameters levels = 10; width = 40; % Initialize matrix tree = repmat(' ', levels, width); % Add branches to tree for i = 1:levels start = width/2 - (i-1); stop = width/2 + (i-1); branches = start:stop; tree(i, branches) = '#'; end % Add trunk to tree trunk_start = floor(width/2) - 2; trunk_stop = floor(width/2) + 2; trunk = levels:levels+3; tree(trunk, trunk_start:trunk_stop) = '|'; % Display tree disp(tree)
You can adjust the levels and width parameters to create trees of different sizes.
levels
width
I hope this helps you!
gistlibby LogSnag