Plotting with full range in the axes

2 visualizaciones (últimos 30 días)
Nikoline K
Nikoline K el 22 de Nov. de 2018
Comentada: Walter Roberson el 12 de Jun. de 2021
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')

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Nov. de 2018
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 comentario
Nikoline K
Nikoline K el 22 de Nov. de 2018
It worked! Thank you!
Hopefully one day I will master this - hope is still there!

Iniciar sesión para comentar.

Más respuestas (1)

Prakhar Mishra
Prakhar Mishra el 12 de Jun. de 2021
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 comentario
Walter Roberson
Walter Roberson el 12 de Jun. de 2021
That appears to be the same code posted originally, except without the original comments. It has the same problem that I described in 2018.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by