How do i create a rectangular like this?

1 回表示 (過去 30 日間)
Dark Shadow
Dark Shadow 2020 年 4 月 6 日
編集済み: Dark Shadow 2020 年 4 月 6 日
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 件のコメント
Subhamoy Saha
Subhamoy Saha 2020 年 4 月 6 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

製品


リリース

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by