How do I make this type of tree in matlab using scatter?

1 view (last 30 days)
Hello, I am trying to make the following tree. I have the matrix a with 0's where I should have white boxes and 1's where I should have square black boxes. However, it is extremely difficult to organize all the boxes in the order to make a tree that looks good without big white spaces being where they should not be.
please help. Thanks
Code below
clear;
clc;
%Makes an array of 0's 20X20
a=zeros(20);
%These following elements are to fill each element in array
%%plotmatrix(a);
a(1,4:7)=1;
a(1,11:14)=1;
a(2,2:12)=1;
a(2,14:18)=1;
a(3,1:11)=1;
a(3,13:19)=1;
a(4,1:3)=1;
a(4,5:9)=1;
a(4,12:19)=1;
a(5,2:4)=1;
a(5,7:8)=1;
a(5,11:13)=1;
a(5,15:16)=1;
a(5,19:20)=1;
a(6,2:5)=1;
a(6,8)=1;
a(6,10:13)=1;
a(6,15:16)=1;
a(6,18:20)=1;
a(7,1:4)=1;
a(7,10:14)=1;
a(7,16)=1;
a(7,18:20)=1;
a(8,1:7)=1;
a(8,10:14)=1;
a(8,18:20)=1;
a(9,1:2)=1;
a(9,4:8)=1;
a(9,10:14)=1;
a(9,16:19)=1;
a(10,1:3)=1;
a(10,6:8)=1;
a(10,11:13)=1;
a(10,16:19)=1;
a(11,1:5)=1;
a(11,8)=1;
a(11,11:12)=1;
a(11,15:19)=1;
a(12,2:6)=1;
a(12,11)=1;
a(12,13:19)=1;
a(13,5:8)=1;
a(13,13:18)=1;
a(14,7:9)=1;
a(14,12:14)=1;
a(15,9)=1;
a(15,12)=1;
a(16,9)=1;
a(16,12)=1;
a(17,9)=1;
a(17,12)=1;
a(18,9)=1;
a(18,12)=1;
a(19,12:14)=1;
a(19,7:9)=1;
a(20,1:9)=1;
a(20,12:20)=1;
x=1;
y=1;
scatter(x,y,'fill', 'square', 'k');
hold on;
y1=ones(1,49);
scatter(1.01:0.01:1.49, y1, 'fill', 'square', 'k');
x=1.5;
scatter( x,y, 'fill', 'square', 'k');
  2 Comments
Walter Roberson
Walter Roberson on 8 Jun 2018
I remember this puzzle coming up a couple of years ago, except I think it had a different image. I seem to remember that a good strategy to solve it was given at the time.
The puzzle involved is to be given the marginal counts of the runs and to use the information to reconstruct the image.

Sign in to comment.

Accepted Answer

Rik
Rik on 8 Jun 2018
How about imshow (or image)? You have a matrix anyway:
imshow(a)
will show your image (although a bit small). You can use imresize to enlarge the image if you like.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!