plot and axis function

1 回表示 (過去 30 日間)
Lisa Lee
Lisa Lee 2017 年 9 月 19 日
回答済み: Lisa Lee 2017 年 9 月 19 日
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

回答 (3 件)

KL
KL 2017 年 9 月 19 日
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 2017 年 9 月 19 日
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 2017 年 9 月 19 日
I got it now. Thank you so much!

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by