필터 지우기
필터 지우기

Matlab function inside Simulink gives parse error

조회 수: 21 (최근 30일)
Wouter
Wouter 2013년 6월 3일
답변: Christopher Magana 2018년 11월 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