ilwookim
ilwookim

Reputation: 1

I got error message about simulink "Output argument is not assigned on some execution paths"

In simulink, I made some model using "MATLAB function"block but I met error message here.

here is code and error message.

function [VTAS,postVTAS]=fcn(mode,initialVTAS,a,t,preVTAS)

if mode == 1
     VTAS = initialVTAS + (a * t) ;
     postVTAS = VTAS;

 elseif mode == 2
     datasize = length(preVTAS);
     lastvalue = preVTAS(datasize);
     VTAS = lastvalue + 0;
     postVTAS = VTAS;

 end

 end

Output argument 'VTAS' is not assigned on some execution paths.

Function 'MATLAB Function' (#36.25.28), line 1, column 26:

"fcn"

Launch diagnostic report.

I think there is no problem about output "VTAS"

please teach me what is a problems.

Upvotes: 0

Views: 4584

Answers (1)

sobek
sobek

Reputation: 1426

As the compiler tells you, under some circumstances there is no output value assigned to VTAS. The reason is that you only assign values to that output if mode is 1 or 2. The compiler doesn't know what values are feasible for mode. To remedy this, you need to make sure that VTAS is assigned under any and all circumstances.

This could be accomplished by, e.g. adding an else construct, like so:

function [VTAS,postVTAS]=fcn(mode,initialVTAS,a,t,preVTAS)

if mode == 1
    VTAS = initialVTAS + (a * t) ;
    postVTAS = VTAS;

elseif mode == 2
    datasize = length(preVTAS);
    lastvalue = preVTAS(datasize);
    VTAS = lastvalue + 0;
    postVTAS = VTAS;

else
    VTAS     = NaN;
    postVTAS = NaN;
end
end

Edit:

Additionally, it would be good practice for the else case to throw an error. This would be helpful for debugging.

As a minor note, for every case, postVTAS is equal to VTAS, so essentially it is superfluous to return both from the function.

Upvotes: 1

Related Questions