make rectangular with vectors

9 ビュー (過去 30 日間)
blunder
blunder 2020 年 3 月 20 日
コメント済み: blunder 2020 年 3 月 21 日
Hi
I write a code for making a rectangular but I have a problem to show one of the sides
I appreciate you for your help
thanks
a=[-1,-1];
b=[-1,1];
c=[1,1];
d=[1,-1];
plot(a,c,'-ok')
hold on
plot(b,c,'-ok')
plot(b,d,'-ok')
plot(c,d,'-ok')
plot(d,a,'-ok')
plot(b,a,'-ok')
plot(b,d,'-ok')
axis([-2,2,-2,2])

採用された回答

the cyclist
the cyclist 2020 年 3 月 20 日
編集済み: the cyclist 2020 年 3 月 20 日
You say that you have a problem with "one" of your lines, but I think you have a deeper conceptual problem with how you tried to do this.
Look at the result of just this code:
a=[-1,-1];
b=[-1,1];
figure
plot(b,a,'-ok')
axis([-2,2,-2,2])
I assume you are intending your point "a" to be the bottom left, and point "b" to be the upper right. But the syntax you used to make the plot is not accurate in that case. When you do
plot(x,y)
you need to make sure that it is that all x coordinates are the first input, and all the y coordinates are the second input. So the line you want would be plotted like this:
a=[-1,-1];
b=[-1,1];
figure
plot([b(1) a(1)],[b(2) a(2)],'-ok')
axis([-2,2,-2,2])
I would do your whole rectangle like this:
x = [-1 -1 1 1 -1]; % All of the x coordinates
y = [-1 1 1 -1 -1]; % All of the y coordinates
figure
plot(x,y,'-ok')
axis([-2,2,-2,2])
  1 件のコメント
blunder
blunder 2020 年 3 月 21 日
thanks for your help
In every condition I had at least one problem with one side or one diameter
after I see your recommendation In last paragraph I found my problem.
x = [-1 -1 1 1 -1]; % All of the x coordinates
y = [-1 1 1 -1 -1]; % All of the y coordinates
I must to follow my direction
So for draw diameters:
x = [-1 -1 1 1 -1 1 -1 1];
y = [-1 1 1 -1 -1 1 1 -1];
figure
plot(x,y,'-ok')
axis([-2,2,-2,2])
thanks a lot

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2020 年 3 月 20 日
plot(a,b,'-ok') % look here
plot(b,c,'-ok')
plot(c,d,'-ok')
plot(d,a,'-ok')

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by