I can't figure out my mistake (conditional)
1 次查看(过去 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
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
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?
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!