Just curios as to why there is a %#codegen at the start of every Matlab function block, and what the point of having the %i.e. u = 4 at the end of the code in the ladder block tread.

If I understand the code properly the %i.e. u = 4 was just for clarification, but my real question is why does Simulink put the %#codegen in all the Matlab function blocks.
Quote 0 0
Great question!

In the MATLAb Function block, %#codegen is what we call a Compilation Directive. It is added to indicate that this MATLAB function is going to go through C-code generation when you hit the 'Deploy to Hardware' button.

For more info on this, see here:

Typically, every MATLAb Function blocks added to a Simulink has this by default. When working with the VEX hardware, make sure to leave this directive as such so that it doesn't affect to 'Deploy to Hardware' behavior later. Do not modify this line!

As for the "%" symbol in MATLAB, this is used to add 'comments' to your code. So yes, in the ladder example, "%i.e. u =4" was a comment that I had added to clarify what that line of code does. Comments have no affect on the function/execution of the code itself. They are merely added for documentation/notation purposes. (In C, you would use // for adding comments)

a = 10;  %Adding comment that a is a variable that is assigned a value of 10
b =a +1; %Increment a by 1 and assign it to b

Quote 0 0
So your saying i should add back my %#codegen back into all my function blocks?
Quote 1 0

Add a Website Forum to your website.