Index exceed number of array elements(1)

조회 수: 1 (최근 30일)
Alexandra Philip
Alexandra Philip 2020년 7월 2일
편집: Alexandra Philip 2020년 7월 6일
I am having some trouble as I recieve this error message:
Index exceeds the number of array elements (1).
Error in ERRORT (line 6)
yearstr=Teststr(7:10);
I am also having trouble to ensuring that for both of the if statements have conditions that if the value is left blank it results in the message and also if the month or year is not a number results in the presented message.
Any suggestions?
  댓글 수: 2
the cyclist
the cyclist 2020년 7월 2일
What is the value of Testdate that you used as input, for which you got this error?
Alexandra Philip
Alexandra Philip 2020년 7월 2일
Testdate=input('What is the test date?(dd-mm-yyyy)','s')

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

채택된 답변

the cyclist
the cyclist 2020년 7월 2일
In your function, the input is a character array, but you convert it to a string. The expression
Testdate(7:10)
would have pulled out the year, but Teststr is a 1-element string (not a length-10 character array), so you cannot access it like that. So, you either need to pull the year out of the character array:
Teststr(7:10)
or do something like this on the string:
extractAfter(Teststr,6)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by