How can I plot a one second sine wave at 1Hz frequency?

14 views (last 30 days)
I need to plot a one second sine wave at 1Hz frequency.
tMin=0;
tMax=1;
tArray = linspace(tMin, tMax, 1000);
freq = [1 5 10];
C= (tArray')*freq;
D=sin(C(:,1));
plot((tArray), D);
axis([0 1 -1.5 1.5]);
This produces a graph of a line but I need to fix it to create a normal one second sine wave.
Thanks, Andrew

Answers (1)

Star Strider
Star Strider on 30 Aug 2015
Edited: Star Strider on 30 Aug 2015
Take out the subscript from ‘C’ in the plot call to plot all three:
tMin = 0;
tMax = 1;
tArray = linspace(tMin, tMax, 1000);
freq = [1 5 10];
C = (tArray')*freq;
D = sin(C); % Plot All Three At Once
plot((tArray), D);
axis([0 1 -1.5 1.5]);
EDIT — To only plot the first two, the ‘C’ assignment changes to:
D=sin(C(:,1:2)); % Plot Two At Once
and to plot only the first and third:
D=sin(C(:,[1 3])); % Plot Two At Once
So you can plot whatever ones you want by specifying them.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!