Index exceeds matrix dimensions. Error

조회 수: 1 (최근 30일)
Catalin
Catalin 2014년 9월 25일
댓글: Image Analyst 2014년 9월 25일
I get the error " Index exceeds matrix dimensions " when I test the function CharactOne bellow. However, I tested individually the second, forth and sixth line of code and they give good results. I don't understand what is the problem with the code, I am guessing it has to do with the if statement , but can't spot the mistake.
function CharactOne= CharactOne(baseType,TCType,u,T,paramsBase,paramsTC)
lambda=-1i*CharactExpLib(baseType,u,paramsBase)-u*CharactExpLib(baseType,-1i,paramsBase);
if strcmp(TCType,'G')|| strcmp(TCType,'IG')
CharactOne=CharactFunSLib(TCType,lambda,T,paramsTC);
else
CharactOne=CharactFunALib(TCType,lambda,T,paramsTC);
end
end
  댓글 수: 4
Catalin
Catalin 2014년 9월 25일
편집: Catalin 2014년 9월 25일
It doesn't. This is the message :
>> CharactOne(baseType,TCType,u,T,paramsBase,paramsTC)
Index exceeds matrix dimensions.
Adam
Adam 2014년 9월 25일
This is one of the many reasons I very rarely write a function nowadays without using validateattributes on every one of my input arguments. It takes very little time and cuts out so many silly errors later in the code.

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

채택된 답변

Guillaume
Guillaume 2014년 9월 25일
You must have a variable called CharacterFactoryOne in your workspace.
newname = CharacterFactoryOne;
clear CharacterFactoryOne
  댓글 수: 3
Guillaume
Guillaume 2014년 9월 25일
Matlab was trying to access the element of the matrix CharacterFactoryOne at row baseType, column TCType, page u, etc., and that matrix didn't have that many element (and probably that many dimensions).
Image Analyst
Image Analyst 2014년 9월 25일
But CharacterFactoryOne was not in the original code that was posted. I thought the problem was that the return argument was the same name as the function name itself (CharactOne).

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by