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 '.^'.

 채택된 답변

David Hill
David Hill 2020년 2월 15일

0 개 추천

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

댓글 수: 2

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

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

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 2월 15일

2 개 추천

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);

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

질문:

2020년 2월 15일

댓글:

2020년 2월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by