Why do my MATLAB plots always begin from zero?

suppose I have the following equation y = cos(n)
to make the discrete plot
figure
subplot(2,2,1);
n = linespace(-10,10,20);
y = cos(n);
stem(y)
xlabel('blah blah blah')
ylabel('y[n]')
title('blah')
grid on
When I save the above code in a MATLAB scipt and run it in MATLAB, my graphs always begin from zero, even when I explicitly specify in the the beginning endpoint be negative linspace(-10,10,50)
Why does it do this?

답변 (2개)

Star Strider
Star Strider 2014년 10월 30일

0 개 추천

The begin and end wherever you tell them to.
Change your stem call to:
stem(n,y)
and see if that improves your result.
Image Analyst
Image Analyst 2014년 10월 31일

0 개 추천

Becuse you're not passing in the "X" values, which you call n. Also, did you know that you can call xlim() to have the axes start and stop wherever you want? Otherwise it tried to pick nice "round" numbers rather than weird fractional numbers. Try this:
n = linspace(-10,10,20);
y = cos(n);
stem(n, y, 'LineWidth', 3)
xlabel('n')
ylabel('cos(n)')
title('Stem of cos()')
grid on;
xlim([min(n), max(n)]);

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

질문:

2014년 10월 30일

답변:

2014년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by