Indexing error when using the plot function.

조회 수: 2 (최근 30일)
Calvin Chang
Calvin Chang 2019년 6월 24일
편집: Adam Danz 2019년 6월 24일
Super basic, but what is wrong with the code below? I'm not understanding. Multiple tutorials state that the code below should be perfectly fine? But I end up receving the error that is shown below the code.
x=[0 1 2 3 4];
y=[2 9/4 38/17 161/72 682/305];
plot(x,y)
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in test (line 4)
plot(x,y)

답변 (1개)

madhan ravi
madhan ravi 2019년 6월 24일
clear all
% you have a variable named plot
  댓글 수: 1
Adam Danz
Adam Danz 2019년 6월 24일
편집: Adam Danz 2019년 6월 24일
+1 To add on to Madhan's answer, you can confirm that by running this line
which plot
which will return "plot is a variable". You should never name a variable "plot".
This recreates your error
plot = 1:4; %variable named plot (gasp!)
%now treat plot as a funciton
x=[0 1 2 3 4];
y=[2 9/4 38/17 161/72 682/305];
plot(x,y)
"Index in position 1 is invalid....."

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by