Plotting with full range in the axes

조회 수: 2 (최근 30일)
Nikoline K
Nikoline K 2018년 11월 22일
댓글: Walter Roberson 2021년 6월 12일
Hi!
I would really like to know how I can make my x-axes with full range, because it stops at 3.
Thank you!
%% Practice 3.6
% Write a script that plots exp(x) and log(x)
% for values of x ranging from 0 to 3.5
clf
x=[0:3.5];
y=exp(x);
plot(x,y,'ro')
hold on
y=log(x);
plot(x,y,'b+')
legend('exp(x)','log(x)')
xlabel('x')
ylabel('exp(x) or log(x)')
title('exp and log on one graph')

채택된 답변

Walter Roberson
Walter Roberson 2018년 11월 22일
x=[0:3.5];
is the same as
x = 0:1:3.5;
which would be x = [0 1 2 3] . That is why your axis stops at 3.
Try
x = linspace(0, 3.5);
  댓글 수: 1
Nikoline K
Nikoline K 2018년 11월 22일
It worked! Thank you!
Hopefully one day I will master this - hope is still there!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Prakhar Mishra
Prakhar Mishra 2021년 6월 12일
clf
x=[0:3.5];
y=exp(x);
plot(x,y,'ro')
hold on
y=log(x);
plot(x,y,'b+')
legend('exp(x)','log(x)')
xlabel('x')
ylabel('exp(x) or log(x)')
title('exp and log on one graph')
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 6월 12일
That appears to be the same code posted originally, except without the original comments. It has the same problem that I described in 2018.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by