why can't use functions, although I know the inputs and outputs are there?

2 Ansichten (letzte 30 Tage)
dafniz91
dafniz91 am 6 Jun. 2016
Bearbeitet: Stephen23 am 6 Jun. 2016
hi, I have a large GUI and in order to save time I am using functions. but only in one function that I input negative and positive integers, generates this following error:
Output argument "sentido" (and maybe others) not assigned during call to
I know that normally this occurs when there are loop errors which doesn't define the output values or there is not enough inputs. but you see, I have checked over and over but I can't find these. also sometimes, it functions.
may be this cucurs because I'm using serial port data for input data of the function. here is the code of the function:
function [sentido] = giro(x,INPUTejeX)
inputejeX=regexp(INPUTejeX, '(+|-)?\d+(\.\d+)?', 'match', 'once')
% inputejeX = regexp(INPUTejeX,'[-]?\d+(\.)?(\d+)?','match','once');
EJEX=str2double([inputejeX{:}]);
ejeX=floor(sum(EJEX)/length(x));
y = floor(sum(ejeX)/length(ejeX));
if y<0%IZQUIERDA
sentido=0;
elseif y>0%DERECHA
sentido=1;
end
end
and the main code of the GUI is here, calling the function:
sentido=3;
Aleatorio=1;
while(sentido~=Aleatorio)
for i=1:length(x);
data00 =fscanf(Arduino);
IncomingString = char(data00);
IncomingString = regexp(IncomingString, '\^', 'split');
INPUTejeXMP1(i,1)= IncomingString(1,3);
end
i=1;
INPUTejeX=INPUTejeXMP1
[sentido] = giro(x,INPUTejeX)
end
I have checked that the input value ('INPUTejeX') is being used and is full of integers. and the 'x', is this: x=[1:1:300];
someone have any idea? any comment is appreciated, since I am begining to be out of ideas and is urgent.
thank you!

Antworten (1)

Stephen23
Stephen23 am 6 Jun. 2016
Bearbeitet: Stephen23 am 6 Jun. 2016
When y is zero then you do not define sentido (and also potentially if y is not scalar, but you do not tell us anything about the values that you are using, so I will assume that y is scalar).
The simplest solution is to avoid the if statement altogether:
sentido = y>0;
Or, if you feel strongly attached to the totally unnecessary if, then you could create a separate zero case like this:
if y==0
sentido = ???
elseif y<0
sentido = 0;
elseif y>0
sentido = 1;
end
or possibly just include it in one of the other two cases, for example like this:
if y<0
sentido = 0;
else
sentido = 1;
end

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by