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

5 次查看(过去 30 天)
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"

采纳的回答

MathWorks Support Team
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2006b

Community Treasure Hunt

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

Start Hunting!

Translated by