How do I plot this square?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I would like to plot a red square with the vertices(1,2),(3,2),(3,4),(1,4).
I would then like to plot 2 blue diagonals of the square using dotted lines.
I need the plotting window in the region of [0,5]x[0,5] and the axes adjusted to look like a square.
Heres what i have so far:
x=[1,2,2,1]
y={2,3,4,1]
2 comentarios
Respuestas (2)
Star Strider
el 2 de Dic. de 2017
Since it’s not homework, here you go:
figure(1)
patch([1 3 3 1], [2 2 4 4],'r')
hold on
plot([1 3], [2 4], ':b', 'Linewidth',1.5)
plot([1 3], [4 2], ':b', 'Linewidth',1.5)
hold off
axis([0 5 0 5])
axis equal
Since you want to learn more, I will let you figure out how it works. There are other ways to create the square (such as fill).. I prefer patch simply because I have more control over what it does.
0 comentarios
Ghady Hajj
el 2 de Dic. de 2017
x = [1 1 3 3 1 1 3];
y = [4 2 2 4 4 4 2];
d1_1 = [1 3];
d1_2 = [4 2];
d2_1 = [1 3];
d2_2 = [2 4];
plot(x,y,'r', 'LineWidth',1)
hold on
plot(d1_1,d1_2,'b', 'LineWidth',1)
plot(d2_1,d2_2,'b', 'LineWidth',1)
% to set both axis from 0 to 5
xlim([0,5])
ylim([0,5])
% to set the increment in each axis to 1
set(gca,'xtick',0:1:5)
set(gca,'ytick',0:1:5)
% or replace these lines:
% x = [1 1 3 3 1 1 3];
% y = [4 2 2 4 4 4 2];
% plot(x,y,'r', 'LineWidth',1)
% by
% rectangle('Position',[1 2 2 2]);
% for simplicity
Hope this will do the job for you. Cheers :)
0 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!