Invalid Matrix Dimensions Error with frprintf

조회 수: 2 (최근 30일)
Adam
Adam 2014년 10월 27일
댓글: Adam 2014년 10월 28일
The following code returns the error after it (ignore the "if true % code end" part):
if true
% code
end
%%%%%%%%%_CODE_%%%%%%%%%
playORquit=5
if playORquit ~= 1
fprintf('THANK YOU FOR PLAYING GUESS-TRON!\n');
fprintf('Here are your results...\n');
fprintf('Number of Trials: %d\n', trial);
end
%%%%%%%%%_ERROR_%%%%%%%%%
Index exceeds matrix dimensions.
Error in TEST_youcandelete (line 2)
fprintf('THANK YOU FOR PLAYING GUESS-TRON!\n');
%%%%%%%%%%%%%%%%%%%%%%%%%
How do I have those strings printed if 'playORquit' doesn't equal '1'
  댓글 수: 1
Star Strider
Star Strider 2014년 10월 27일
The entire if-block and enclosed statements execute without error for me with ‘playORquit=5’, and setting ‘playORquit=1’ results in their not being executed. I don’t see the error.

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

채택된 답변

Siddharth Sundar
Siddharth Sundar 2014년 10월 28일
Nothing in the above code seems to point towards any error. You might have a variable called fprintf defined in your workspace, causing MATLAB to recognize fprintf to be a matrix you are trying to index into with your fprintf statement. Please check this and use a different variable name if you do have a variable called fprintf.
  댓글 수: 1
Adam
Adam 2014년 10월 28일
Thanks, I figured out that I made fprintf= to something by accident, so you were right. Thanks again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by