plotting shapes in matlab
2 views (last 30 days)
Show older comments
Mahmoud Mohammed
on 29 Nov 2015
Commented: Geoff Hayes
on 29 Nov 2015
Dear all
I have a task to draw a shape like star in matlab and I need someone to help me to do this and this is the shape .
Thanks
0 Comments
Accepted Answer
Geoff Hayes
on 29 Nov 2015
Mahmoud - as this is a homework assignment, we can only give hints on how to proceed. In this case, break the star down into its components which are the five lines. How would you plot each line? You know the (x,y) coordinate for the start and the end point for each line so you can determine its slope. From that you can determine the equation for the line which you can then plot.
All lines will have the same set of points along the x-axis so we can initialize this set as
x = linspace(2,4,50);
(In the above, x will be an array of 50 elements that are linearly spaced between 2 and 4.)
Now, if we consider the horizontal line which starts at (2,4) and ends at (4,4), then the equation for this line (as an anonymous function) is
y = @(x)4;
which we can then plot as
plot(x,y(x));
2 Comments
Geoff Hayes
on 29 Nov 2015
Yes, that is how I would go about doing this assignment. There may be alternate ways to do this, but without knowing how this relates to what you have learned in class...I am guessing that this assignment is to demonstrate the understanding behind the equation of a line (slope, intercepts, etc.)
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!