Help Needed with Plotting 2d graph
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am getting the error in my function code: Error using .* Matrix dimensions must agree, so i tried it without the "." and it still doesn't work. what am i doing wrong?
I am plotting a function called plot04 that plots yi = sin(x*i*π), where i = 1, 2, 3. I am defining the length of the guitar string to be an array of 100 equally spaced values over the interval [0, 1].
I know I am supposed to enable hold using the command hold on. Then, call plot three times to plot each harmonic. For the first harmonic, I have to set the linewidth property to 1. For the second harmonic, I have to set the linewidth property to 2. And for the third harmonic, I have to set the linewidth property to 3. Third, I have to disable hold using the command hold off.
code
function [y] = plot04(x,i)
x= 0:.01:1
i= [ 1 2 3]
y= sin (x .* i .* pi)
hold on
plot(x,y,'LineWidth',1)
plot(x,y,'LineWidth',2)
plot(x,y,'LineWidth',3)
hold off
ylabel('Amplitude')
legend('first harmonic','second harmonic','third harmonic')
lines = {'first harmonic','second harmonic','third harmonic'}
legend(lines)
it's supposed to look like this: http://i1308.photobucket.com/albums/s617/pingchu93/Graph1_zps62e3327f.jpg
0 comentarios
Respuesta aceptada
Walter Roberson
el 15 de Oct. de 2012
y = sin (x.' * i .* pi)
to get y to be correct for your purposes.
Setting the line width the way you do is not correct: you are drawing the same lines over and over again, rather than drawing different lines each time or rather than setting the linewidth property of existing lines. Consider assigning the output of plot() to a variable and working with that variable.
Más respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!