How can i do that?
조회 수: 3 (최근 30일)
이전 댓글 표시
a. Ask the user for the length of the edge.
b. Define the axes of the chart according to the entered edge length.
c. Draw the square with the origin points (0,0) and step intervals in 0.5 units.
D. Then draw the edges in a straight line. (For example, if the user enters the number 20
You should get the image in the picture below.)
The drawing should have a star as above
how can i do that?

댓글 수: 5
채택된 답변
Jan
2021년 3월 24일
편집: Jan
2021년 3월 24일
a = input('Bir sayi giriniz=');
figure;
axes('NextPlot', 'add', ... % as: hold on
'XLim', [-1, a+1], 'YLim', [-1, a+1], ...
'DefaultLineMarkerSize', 3); % More compact code
Delay = 0.05;
for b = 0:0.5:a
plot(b, 0, '*k')
pause(Delay)
end
for b = 0:0.5:a
plot(0, b, '*k')
plot(a, b, '*k')
pause(Delay)
end
for b = 0:0.5:a
plot(b, a, '*k')
pause(Delay)
end
댓글 수: 4
Walter Roberson
2021년 3월 24일
편집: Walter Roberson
2021년 3월 24일
In order to draw a thinner line, you will need a monitor that is higher resolution, as you are already drawing a line that is only 1 physical pixel thick, unless you happen to be displaying on an iPhone or similar very-high-resolution display.
get(0, 'ScreenPixelsPerInch')
get(0, 'ScreenSize')
get(0, 'MonitorPositions')
1/2 point is (1/72)/2 inches, multiply by (99 pixels per inch) = 0.6875 pixels
Reference: "The plot above uses the default MATLAB line width of 0.5 points."https://blogs.mathworks.com/steve/2019/02/22/making-your-plot-lines-thicker/ (Steve was part of the MATLAB graphics implementation team)
추가 답변 (1개)
Walter Roberson
2021년 3월 23일
You need six loop phases.
- draw the bottom stars left to right
- draw stars up on the left and right simultaneously
- draw stars on the top from left to right
- draw the line on the bottom from left to right, with shorter pause than you use for the stars
- draw the line up from the bottom on left and right simultaneously, using a shorter pause than for the stars
- draw the line across the top from left to right, using a shorter pause than for the stars
I already showed you in a previous post how to draw animated lines of stars using plot() with '*k' and drawing with different changing limits.
I already showed you in a previous post how to draw animated lines using plot with '-k' and different changing limits.
You already knew about hold on, and about pause()
I already showed you in a previous post how to change the drawing limits over time.
You already have all the tools you need to solve this.
There are some advanced techniques to make the drawing more efficient. You could look at animatedline() for example.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!