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

 Réponse acceptée

Geoff Hayes
Geoff Hayes le 29 Nov 2015

0 votes

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));
You can refer to plot to see how you may adjust the plot so that it appears as a red dashed line.

2 commentaires

Mahmoud Mohammed
Mahmoud Mohammed le 29 Nov 2015
Thanks for quick response but you want to say that i have to find five equations for the five lines then plotting them and i will get the shape?
Geoff Hayes
Geoff Hayes le 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.)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by