Index exceeds the number of arrays

조회 수: 91 (최근 30일)
Liam Crocker
Liam Crocker 2020년 8월 7일
댓글: KSSV 2020년 8월 7일
A friend of mine is doing the exact same code
My code:
A = 4;
W = 0.6;
T = 0:10;
x = A*cos(W'*T')
plot(T',x')
title('Displacement versus Time')
xlabel('Time')
ylabel('Displacement')
Index exceeds the number of array elements (24).
Error in Assignment1Q3 (line 6)
title('Displacement versus Time')%Name of graph
His code
% Plot the dispalcment vs the time
plot(t,x,'Linewidth',2)
title('Displacement vs Time')
xlabel('Time in s')
ylabel('Displacement in cm')
Why am I getting this error and he is not? I am really unsure when we have just named them different things, but the layout is excatly the same. I am pretty new to Matlab and I'm not even sure if this is the right place to post the question. If it isn't please point me in the right direction.
Thanks, Liam

채택된 답변

KSSV
KSSV 2020년 8월 7일
Try to clear the variables, before using your code. There is no error in your code. It should work.
clc; clear all;
A = 4;
W = 0.6;
T = 0:10;
x = A*cos(W*T)
plot(T,x)
title('Displacement versus Time')
xlabel('Time')
ylabel('Displacement')
  댓글 수: 5
Liam Crocker
Liam Crocker 2020년 8월 7일
So I just restarted matlab and it fixed my problem
KSSV
KSSV 2020년 8월 7일
It means, there is a variable named title in your workspace....clear all/ clear title should have helped.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by