How Can You Handle Unassigned Outputs in Simulink's Embedded MATLAB Function?

In summary, the conversation discusses using the Embedded MATLAB Function in Simulink and the issue of outputting a value for the variable 'out' in certain conditions. The speaker is seeking advice on how to properly assign an initial value for 'out' to ensure it changes only under specific conditions.
  • #1
ilconformista
18
0
Hello everyone!
In Simulink , I use the Embedded MATLAB Function

function out = fcn(meas)

if meas>10
out = 4;
elseif meas<=0
out=2;
end

And I get this message:
Output argument 'out' is not assigned on some execution paths.

I would like the variable 'out' to change its value only if either of these conditions is true.
So I guess I have to give 'out' an initial value that is valid only for the first cycle of the program.
Does anyone know how I can do that?

Thanks!
 
Physics news on Phys.org
  • #2
ilconformista said:
I would like the variable 'out' to change its value
What will the function return if meas is in 0<meas<=10? You have to specify an else with the if-else, because the variable would otherwise not be defined when the two conditions you have given are not satisfied, and the function would have nothing to return.
 

1. What is a Matlab function in Simulink?

A Matlab function in Simulink is a block that allows you to incorporate custom Matlab code into your Simulink model. It can be used to perform mathematical calculations, manipulate data, and create custom algorithms.

2. How do I create a Matlab function in Simulink?

To create a Matlab function in Simulink, you can use the "Matlab Function" block from the Simulink library. You can then write your custom Matlab code within the block's editor or import an existing .m file.

3. Can I use Simulink built-in functions in a Matlab function block?

Yes, you can use Simulink built-in functions in a Matlab function block. These functions can be accessed by using the "simulink" prefix before the function name (e.g. simulink.cos).

4. How do I pass inputs and outputs to a Matlab function in Simulink?

You can pass inputs and outputs to a Matlab function in Simulink by using the "Inport" and "Outport" blocks and connecting them to the appropriate ports on the Matlab function block. You can also specify the size, data type, and other properties of the inputs and outputs.

5. Can I debug my Matlab function block in Simulink?

Yes, you can debug your Matlab function block in Simulink. You can use breakpoints, step through your code, and view the values of variables to troubleshoot any errors or issues in your code.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
996
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
822
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top