I'm getting a matrix subscript index error

The error is:
Subscript indices must either be real positive integers or logicals.
I'm referencing each matrix using the following:
time_stamp = [time_stamp; datestr(now, 31)];
fprintf(fid, %s ... ,time_stamp(end, 1:end), ...);
This is in a while loop and time_stamp grows each cycle through by one string. Why am I getting this error if I'm using 'end' to reference the matrix?

댓글 수: 5

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 24일
How are we supposed to know ? please post your code with the line causing the error
Brian
Brian 2013년 10월 25일
Those are the two lines of code causing the error.
Matt J
Matt J 2013년 10월 25일
편집: Matt J 2013년 10월 25일
What does DBSTOP tell you? In particular, when code execution stops at the K>> prompt and you execute
K>> time_stamp(end, 1:end)
what is the result?
Brian
Brian 2013년 10월 25일
The result gives me the error when I try doing the step-through method for debugging.
Matt J
Matt J 2013년 10월 25일
편집: Matt J 2013년 10월 25일
I'm not sure you answered my question. What specifically is the output (include error messages please) when you execute this expression in isolation
K>> time_stamp(end, 1:end)

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

답변 (2개)

Walter Roberson
Walter Roberson 2013년 10월 25일

0 개 추천

You assigned a value to a variable named "datestr" and then tried to use datestr() as a function call.

댓글 수: 1

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 25일
Brian commented
datestr() is a built-in function already created in Matlab. I have not assigned anything to it.

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

Kelly Kearney
Kelly Kearney 2013년 10월 25일

0 개 추천

Perhaps you accidentally made end the name of a variable? At that line, what does
which end
return?

댓글 수: 2

Matt J
Matt J 2013년 10월 25일
No. It is impossible to make end the name of a variable.
Brian
Brian 2013년 10월 25일
No, I made sure I never tried assigning a variable to end.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 10월 24일

댓글:

2013년 10월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by