Matlab function inside Simulink gives parse error

21 次查看(过去 30 天)
I have included the Matlab Function block in a Simulink diagram to call a matlab function, http://www.mathworks.nl/help/simulink/slref/matlabfunction.html.
Now when I want to simulate the Simulink diagram I get the error:
Errors occurred during parsing of MATLAB function 'MATLAB Function'(#384)
I however do not find any errors in my matlab function script:
function out = Sigma(xyz,x1,u)
x = xyz(1);
y = xyz(2);
z = xyz(3);
out = [-x^3 + 3*x + 2 + 5*y - z + u; ...
-0.8 - x^2 - 2*x - y; ...
0.005*(4*(x1 + 1.77) - z)];
end
The input xyz is a mux-ed signal with length 3, x1 and u are scalar values.
So what is going wrong? Can anyone look threw my files?
It contains three files. - main.m, the main file in some variables are declared and which runs the simulink model - Sigma.m, a copy of the matlab function - HindmarshRose.mdl, the simulink model.
  1 个评论
Kaustubha Govind
Kaustubha Govind 2013-6-3
编辑:Kaustubha Govind 2013-6-3
Please scroll down through the list of errors in the popup window and see if you can find more details about the error, especially one pointing to a line number in your code.

请先登录,再进行评论。

采纳的回答

Wouter
Wouter 2013-6-8
It turns out you have to initialize the output before calling any Matlab code since otherwise Matlab does not know the length of the output.
function out = Sigma(xyz,x1,u)
out = zeros(3,1);
x = xyz(1);
y = xyz(2);
z = xyz(3);
out = [-x^3 + 3*x + 2 + 5*y - z + u; ...
-0.8 - x^2 - 2*x - y; ...
0.005*(4*(x1 + 1.77) - z)];
end

更多回答(2 个)

Dragoș Vasile
Dragoș Vasile 2014-4-10
Hello,
I have the same problem and I have already tried to put the output size but the error still appears.
The code is in a Matlab function in Simulink.
Here is my code:
function [ Ts, Tq ] = Ts_function( PWM ) %THRUST_AND_TORQUE Summary of this function goes here % Detailed explanation goes here
P = [1000 1200 1500 1600 1650 1700 1750 1800 1850 1900 1950 2000];
Fq= [0 50 75 84 91 94 100 109 113 119 121 125];
RPM = Fq * 60;
Ts1 = 8.9e-7*RPM.^2.3314;
Tq1 = 1.0798e-005*Ts1;
Thrust = interp1(P,Ts1,PWM,'spline'); Torque = interp1(P,Tq1,PWM,'spline');
end

Christopher Magana
Christopher Magana 2018-11-30
I have the same problem and all I'm trying to do is use Bitconcat in simulink...It is not even my function and its throwing an error for it.

类别

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

产品

Community Treasure Hunt

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

Start Hunting!

Translated by