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 Comments

This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Jan
Jan on 23 Mar 2021
I see an animated image, which is such tiny, that I cannot recognize anything.
The description of the problem starts with "a. Ask the user for the length of the edge." This might be a simple |input < command, or a GUI based solution. The readers have to guess, what your problem is with this part.
I suggest to try it and to ask specific questions in the forum.
"The only thing I wanted from you was how to connect the stars in the animation part ...." - then it is not useful to post this part of the question also: "a. Ask the user for the length of the edge."
"How do you know I'm not doing abc steps?"
Because you specifically told us that you discarded your previous work.
"If you can't find a solution, please don't mind, I have already done the steps you said."
I had already showed you how to draw lines and you could see the (very small) difference between that and drawing the stars. If you had in fact solved drawing the stars then the difference to drawing the line would have been literally one character, '*k' vs '-k'
"I could not get the answer I wanted"
What you appear to have wanted was a complete solution, considering that I had already shown you how to draw animated lines and stars.
Jan
Jan on 24 Mar 2021
@ukulele: It is still not clear what you are exactly asking for.
It is possible that you get an answer if you post your current code and ask a specific question concerning the next step.
Jan
Jan on 24 Mar 2021
@ukulele: Please do not remove the contents of your question after an answer has been posted. The nature of this forum is sharing problems and solutions. The deleting of the text of a question makes the answer meaningless. Therefore this is considered as an impolite act.

Sign in to comment.

 Accepted Answer

Jan
Jan on 24 Mar 2021
Edited: Jan on 24 Mar 2021
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 Comments

Jan
Jan on 24 Mar 2021
Edited: Jan on 24 Mar 2021
what is the "example above"? When you combine what with "the '-' command" and what is "the '-' command"? Where is a spece between what?
Maybe you want to draw lines between the corners?
plot([0, a, a, 0, 0], [0, 0, a, a, 0], '-k')
The default line width is 0.5, with the unit being "points". 1 "point" is 1/72 of an inch, so 0.5 points is 1/144 of an inch, which is probably between 1/2 and 3/4 of a pixel depending on your screen resolution. When you ask for line width 0.01 you are asking for 1/100 * 1/72 = 1/7200 of an inch, or roughly 352 nanometers. Basically you are asking for the line to be drawn in near Ultraviolet.
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')
ans = 99
get(0, 'ScreenSize')
ans = 1×4
1 1 1920 1200
get(0, 'MonitorPositions')
ans = 1×4
1 1 1920 1200
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)
Jan
Jan on 24 Mar 2021
@ukulele: Please post the code you have tried. How do you check ifg the line is thin? For me the standard width of 0.5 is exactly 1 pixel on my monitor. It is impossible to draw a thinner line.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 23 Mar 2021

0 votes

You need six loop phases.
  1. draw the bottom stars left to right
  2. draw stars up on the left and right simultaneously
  3. draw stars on the top from left to right
  4. draw the line on the bottom from left to right, with shorter pause than you use for the stars
  5. draw the line up from the bottom on left and right simultaneously, using a shorter pause than for the stars
  6. 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.

Asked:

on 22 Mar 2021

Commented:

Jan
on 24 Mar 2021

Community Treasure Hunt

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

Start Hunting!