To plot a sine wave in matlab, you can use the plot
function. The plot
function takes in two arrays, one for the x-values and one for the y-values. In this case, the x-values will represent the domain of the sine wave, and the y-values will represent the values of the sine wave.
You can generate an array of x-values using the linspace
function. linspace
takes in the starting value, ending value, and number of points to generate between those values. For example, to generate an array of 100 x-values between 0 and 2pi (the period of a sine wave):
main.m28 chars2 lines
Then you can calculate the y-values of the sine wave using the sin
function:
main.m12 chars2 lines
Finally, you can plot the sine wave using the plot
function:
main.m12 chars2 lines
This will generate a simple plot of a sine wave. You can customize the plot by adding axis labels, changing the color or line style, and adding a title. For example:
main.m70 chars5 lines
This will plot a red, dashed sine wave with x-axis label "x", y-axis label "sin(x)", and title "Sine Wave".
gistlibby LogSnag