필터 지우기
필터 지우기

I can't figure out my mistake (conditional)

조회 수: 2 (최근 30일)
Kratos
Kratos 2014년 9월 30일
답변: Image Analyst 2014년 9월 30일
Can someone please help?
It keeps saying Undefined function or variable "domIndex"
Error in personalityTest line 38
dom = strcat(pVector{domIndex},'_',subT(1));
function [ dom, rec, wings ] = personalityTest( type,pVector, subT )
Vector = cell(10);
remain = pVector;
for i = 1:10
[token,remain] = strtok(remain);
pVector{i} = token;
end
if (type(1)-65 > 26)
dom = false;
type(1) = 65 + (type(1)-97);
else
dom = true;
end
for i = 1:10
if (strcmp(pVector{i},type) == 1)
if (dom)
domIndex = i;
recIndex = mod(domIndex + 5,10);
else
recIndex = i;
domIndex = mod(recIndex + 5,10);
end
if domIndex == 1
rightIndex = 10;
else
rightIndex = i-1;
end
if domIndex == 10
leftIndex = 1;
else
rightIndex = i+1;
end
break;
end
end
dom = strcat(pVector{domIndex},'_',subT(1));
rec = pVector{recIndex};
wings = strcat(pVector{leftIndex},32,pVector{rightIndex});
return;
end
  댓글 수: 1
dpb
dpb 2014년 9월 30일
Two possibilities --
a) you write 'domindex' in the error message but all references in the function are 'domIndex'. If the message spelling isn't a typo, that's a problem, or (probably more likely);
b) only if (strcmp(pVector{i},type) == 1) is TRUE will domIndex be defined and if it isn't, one must conclude the IF is failing.
Use the debugger and see where things go south...

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

답변 (1개)

Image Analyst
Image Analyst 2014년 9월 30일
Just step through your code and you'll see the "if" statement inside the for loop is never true and so domindex never gets assigned by the time you need to use it right after the for loop. What do you want to do in that case? What do you want domindex to be if the "if" never gets entered?

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by