I want to plot a graph of y against x:
x=[0:2*pi]
y=exp(1)^x
plot(x,y)
But this error showed:
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is
square and the power is a scalar. To perform elementwise matrix powers, use '.^'.

 Respuesta aceptada

David Hill
David Hill el 15 de Feb. de 2020

0 votos

x=0:.01:2*pi;
y=exp(1).^x;
plot(x,y)

2 comentarios

justin pau
justin pau el 15 de Feb. de 2020
what does the change mean? thanks
David Hill
David Hill el 15 de Feb. de 2020
.^ needed for element-wise array operations
0:.01:2*pi splits up the interval into finer steps for plotting

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 15 de Feb. de 2020

2 votos

Don't try to raise exp(1) to the power of x. Just use exp on the array x directly.
x = 1:5;
y = exp(x);

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 15 de Feb. de 2020

Comentada:

el 16 de Feb. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by