Home > Software engineering >  How to declare variable type for code generation in MATLAB
How to declare variable type for code generation in MATLAB

Time:04-19

Consider the following variable declaration in C code:

Counter_Type counter_var;

It is a C code that a counter_var is defined with a specific type Counter_Type.

my question is: How it would be possible to declare a variable type which is used inside a MATLAB function in Simulink lead the generated code generates that variable with that specific type.

For instance consider the following code which is a simple odd number adder written in MATLAB as a MATLAB fucntion:

function Sum = sum_oddfcn(N)
Sum = 0; count = 1;
while ne(count,N)
    if mod(count,2) ~= 0
        Sum = Sum   count;
    end
    count = count   1;
end
end

Now I want to know if there is a way to declare the count variable declared in the above function to be generated with a type of Custom_Type variable.

CodePudding user response:

you can use add parameter in matlab function and define datatype in base workspace.

  • Related