Why do I receive a class mismatch error when I pass an input to an Embedded MATLAB function in Simulink 6.5 (R2006b)?

4 views (last 30 days)
I have an Embedded MATLAB function in a Simulink model that consists of the following code:
function [a, secondOutput] = fcn(input)
a.b = single(1);
a.c = 1;
secondOutput = 1;
I receive the following error when I run this model:
Class mismatch (single ~= double). The class to the left is the class of the left-hand side of the assignment. Function 'Embedded MATLAB Function' (#958.143.146), line 5, column 1:"a.b"

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This issue occurs because the data type of the input is not explicitly specified and this causes Simulink to guess the data types of the variables in the Embedded MATLAB function. The expression 'single(1)' in the Embedded MATLAB function is guessed to be a scalar double rather than a single and this is the cause of the mismatch.
To work around this issue, you can:
1. Explicitly specify the data type of the input by opening the Model Explorer from the View menu, going to the 'MATLAB Embedded Function' subpane under 'example2', clicking on 'input' in the list of variables in the MATLAB Embedded Function and changing the Type of this variable to 'double'.
2. Let the statement 'secondOutput = 1' precede the statement 'a.b = single(1)'.
3. Remove the input from the Embedded MATLAB function - i.e. do not pass any inputs to the function.

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2006b

Community Treasure Hunt

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

Start Hunting!