plot and axis function

1 visualizzazione (ultimi 30 giorni)
Lisa Lee
Lisa Lee il 19 Set 2017
Risposto: Lisa Lee il 19 Set 2017
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

Risposte (3)

KL
KL il 19 Set 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
For the axis , it is,
axis([xmin xmax ymin ymax])

Lisa Lee
Lisa Lee il 19 Set 2017
What I don't understand is why not axis([1 100 -1.1 1.1]) instead of axis([0 100 -1.1 1.1])? The default x array is the index number, which should start with 1. Am I right?

Lisa Lee
Lisa Lee il 19 Set 2017
I got it now. Thank you so much!

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by