This is what I tried. All I get is a square. I thought the number of x and y gives the figure.
x1=1;y1=-1;x2=-1;y2=1;x3=1;y3=1;x4=-1;y4=-1;x5=1;y5=1;x6=-1;y6=1;
plot(x1,y1,'o',x2,y2,'*',x3,y3,'h',x4,y4,'d',x5,y5,'k',x6,y6,'g')
axis([-2 2 -2 2])
What am I doing wrong? Please help!
Thanks for your time.

댓글 수: 2

Image Analyst
Image Analyst 2012년 8월 5일
Points 3 and 5 are the same, and points 2 and 6 are the same, so they'll plot at exactly the same place.
T
T 2013년 9월 14일
편집: Azzi Abdelmalek 2013년 9월 15일
This is how I did it:
theta= 0:pi/3:2*pi
r= ones(1,7)
polar(theta,r)

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2012년 8월 5일
편집: Image Analyst 2012년 8월 5일

1 개 추천

Try this:
theta = 0:60:360;
x = cosd(theta);
y = sind(theta);
plot(x, y, 'b-', 'LineWidth', 3);
axis square;
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Plot markers if you want.
plot(x(1),y(1),'o',x(2),y(2),'*',x(3),y(3),'h',...
x(4),y(4),'d',x(5),y(5),'s',x(6),y(6),'x', ...
'MarkerFaceColor',[.49 .1 .63], 'MarkerSize', 30)

댓글 수: 2

Thanks a lot, Image Analyst. Is that linspace? The way you used theta. I got exacly what I was aiming for.
Thanks for your time.
Image Analyst
Image Analyst 2012년 8월 8일
It wasn't linspace(), but you could use linspace() if you wanted to, to get x.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

rahul sharma
rahul sharma 2017년 1월 6일

1 개 추천

a=4; b=4;c=4; x=[a c*0.5 -b*0.5 -a -c*0.5 b*0.5 a]; y=[0 c*0.866 b*0.866 0 -c*0.866 -b*0.866 0];
plot(x,y); axis([-6 6 -6 6])
Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 5일
편집: Azzi Abdelmalek 2012년 8월 5일

0 개 추천

% use this function
function hexagon(cote,x0,y0)
%cote= side size;,(x0,y0) exagon center coordinates;
x=cote*[-1 -0.5 0.5 1 0.5 -0.5 -1]+x0
y=cote*sqrt(3)*[0 -0.5 -0.5 0 0.5 0.5 0]+y0
plot(x,y,'r','Linewidth',4);grid;
axis([ x0-cote x0+cote y0-cote y0+cote]);
%example
hexagon(10,5,8)

댓글 수: 4

Thank you Azzi Abdelmalek, I finally understood how functon works.
Thanks for your time.
Suvendu Konai
Suvendu Konai 2013년 7월 5일
do i need to include any tools for running this function? its not running by only copy paste !
sravankumar v
sravankumar v 2018년 8월 31일
how to name each vertex of hexagon?
Image Analyst
Image Analyst 2018년 8월 31일
What do you mean by "name"? Like you want to use text() to place a string next to each vertex?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

태그

질문:

2012년 8월 5일

댓글:

2018년 8월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by