plot and axis function
2 views (last 30 days)
Show older comments
I am confused about how plot and axis functions are used here. Normally, plot should be used as plot(time, ySound), but here plot(ySound) can work by itself. Why?
I understand that in axis([0 100 -1.1 1.1]), the first two digits actually represent the first 100 samples. However, shouldn't the first two digits of the axis function be used to represent the limits of the time?
sampleFreq = 8000; freqMiddleC = 261.63; amplitude = 1;
time = linspace(0, 2, sampleFreq * 2); % Corresponds to 2 sec
ySound = amplitude * sin(2 * pi * freqMiddleC * time);
sound(ySound, sampleFreq); % Plays the sound
figure(1);
plot(ySound, 'o', ..... % Places a circle at each point
'MarkerSize', 6, ... % Make circle larger
'MarkerFaceColor', 'r', 'MarkerEdgeColor', 'r');
axis([0 100 -1.1 1.1]); xlabel('time');
Thanks in advance,
- Lisa
0 Comments
Answers (3)
KL
on 19 Sep 2017
Take this simple example,
t = 1:10;
y = 10*t;
Now use just plot(y) in two ways to see the difference.
figure(1)
plot(y) %blue
hold on
plot(y(6:10)) %red
and now try to plot with x axis explicitly specified.
figure(2)
plot(t,y) %blue
hold on
plot(t(6:10),y(6:10)) %red
axis([xmin xmax ymin ymax])
0 Comments
See Also
Categories
Find more on Line 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!