I'm an amateur at MATLAB and I know how to do the basic stuff such as plotting functions, writing M files, functions, for loops, etc but I've be tasked to do something I have never done before.
I have to draw this figure which resembles a Tree or Home (2D childs drawing), and I know all of its points: (6,1), (8,1), (6, 3) (8,3) makes the base of the house (and the diagonals are drawn too) and then the points (6,3), (7,4), (8,3) make the roof.
How do I connect the points in a way that it resembles what I'm looking at?
Thanks.
$\endgroup$ 31 Answer
$\begingroup$points = [ 6 1 8 1 6 3 8 3 7 4];
sequence = [1 2 4 3 1 4 2 3 5 4];
plot(points(sequence, 1), points(sequence, 2), '-o')
set(gca, 'XLim', [5, 9], 'YLim', [0, 5],'DataAspectRatio', [1 1 1])
figure(gcf)Perhaps more idiomatically:
points = [ 6 1 8 1 6 3 8 3 7 4];
sequence = [1 2 4 3 1 4 2 3 5 4];
u = points(sequence, :);
plot(u(:, 1), u(:, 2), '-o')
set(gca, 'XLim', [5, 9], 'YLim', [0, 5],'DataAspectRatio', [1 1 1])
figure(gcf) $\endgroup$ 2