I can't figure out my mistake (conditional)

1 visualización (últimos 30 días)
Kratos
Kratos el 30 de Sept. de 2014
Respondida: Image Analyst el 30 de Sept. de 2014
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 comentario
dpb
dpb el 30 de Sept. de 2014
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...

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 30 de Sept. de 2014
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?

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by