Output argument is not assigned on some execution paths for Embedded matlab function

조회 수: 7 (최근 30일)
Qingbin
Qingbin 2013년 1월 11일
편집: Cedric 2017년 10월 24일
For a single input u to the embedded matlab function using the following code:
if u>0
y=1;
end
if u<0
y=-1;
end
if u==0
y=0;
end
gives error: "output argument 'y' is not assigned on some execution paths."
I don't know why the codes above are not working. Instead, I have to use if...elseif...else structure.

답변 (3개)

Cedric
Cedric 2013년 1월 11일
편집: Cedric 2013년 1월 11일
Look at the following:
>> u = [1 2 3] ;
>> if u < 2, fprintf( 'OK\n' ) ; end
>> if u > 2, fprintf( 'OK\n' ) ; end
>> if u == 2, fprintf( 'OK\n' ) ; end
>> if u == [1 2 3], fprintf( 'OK\n' ) ; end
OK
>>
EDIT: Also, and the error might come from that..
>> [NaN < 0, NaN > 0, NaN == 0]
ans =
0 0 0
Testing equalty of arrays, or arrays/scalar, requires a little more work usually. Look up:
>> doc any
>> doc all
>> doc isnan
>> doc isequalwithequalnans
EDIT: in your case with the error, you should probably manage NaN cases. If M-Lint were indicating (as a tip) that the output arg. might not be assigned, I would guess that the array/scalar tests could be a cause.
EDIT: if you know that u is a scalar (this should be tested if you wanted to create a robust function) and not NaN, just build an if u>0, .. elseif u<0, .. else.. end conditional statement. It is better than your series of statements in the sense that it doesn't test conditions from statements below one whose condition was true.
Cheers,
Cedric
  댓글 수: 5
maryam
maryam 2014년 1월 28일
I have the same problem. Please share how you solved it finally.
Qingbin
Qingbin 2014년 1월 31일
FYI, I used if...elseif...end structure instead of if...end...if end structure.

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


Sean de Wolski
Sean de Wolski 2013년 1월 11일
How about:
y = sign(u)
?
  댓글 수: 1
Qingbin
Qingbin 2013년 1월 11일
I am trying to test the assignment structure for the embedded matlab function. So it doesn't necessarily be sign (u).

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


Dr Yu Lu
Dr Yu Lu 2016년 10월 21일
Have you fixed this? I have similar problem
  댓글 수: 4
Stephen23
Stephen23 2017년 10월 24일
Cause: if num_frames is less than one then segSNR is never defined.
Solution: put a dummy value at the start of the function, e.g. segSNR = [];
Tip: you should avoid using global variables.
Walter Roberson
Walter Roberson 2017년 10월 24일
Your section
if (clean_length ~= Enhanced_length)
disp('Error: Both Speech Files must be same length.');
return
end
does not assign to some output variables. You can switch to error() instead of disp/return, or you can switch to assert() instead of disp/return, or you can assign outputs to all of the variables for that case.
Also, your segSNR is not assigned to unless at least one iteration of the for loop is done; the way you calculate num_frames it can come out less than 1.
Question: why are you overwriting all of segSNR on each iteration of the loop?

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

카테고리

Help CenterFile Exchange에서 Simulation, Tuning, and Visualization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by