How do i create a rectangular like this?

1 visualización (últimos 30 días)
Dark Shadow
Dark Shadow el 6 de Abr. de 2020
Editada: Dark Shadow el 6 de Abr. de 2020
Hello.
I need help with a school project in Matlab.
I have to create a rectangular shape (script) like the code below without using the ''rectangle'' command, and the dimensions of the rectangular are to be inserted with the ''input'' command and the center of the rectangular is the origin of XY axis.
Can you help me?
Looking forward to hearing from you as soon as possible. I hope you can help me.
Thank you!
clear all
close all
clc
a = input('Dim 1: '); % Width for ex: Dim 1: 5(cm)
b = input('Dim 2: '); % Length for ex: Dim 2: 10(cm)
width = a;
length = b;
x_center = 0;
y_center = 0;
xl = x_center - width/2;
yb = y_center - length/2;
rectangle('Position',[xl, yb, width, length]) % I have to eliminate this line and reformulate it without using "rectangle" command
grid on
xlim([-100, 100]);
ylim([-100, 100]);
xL = xlim;
yL = ylim;
line([0 0], yL)
line(xL, [0 0])
  1 comentario
Subhamoy Saha
Subhamoy Saha el 6 de Abr. de 2020
As this is a school project, I'm not giving the direct solution. I'm sure you can do it by yourself.
You already have the answer hidden in your script. Just use 4 lines. You have drawn x and y axes using the same. Just modify those an you will have your rectangle.
Create end point coordinates from the dimension values. The following code will draw a line between point (x1, y1) to (x2, y2). By this way you have to write 4 lines of code to draw 4 lines.
line([x1, x2], [y1, y2])
However, you can also create a matrix to draw multiple lines in one go. See the matlab documentation for details.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Productos


Versión

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by