Function call failed when calling matlab function inside function block

22 vues (au cours des 30 derniers jours)
Davide
Davide le 8 Avr 2024
Commenté : Davide le 8 Avr 2024
clear
close all
clc
x = sym('x',[3 1],'real');
u = sym('u',[1 1],'real');
%% Plant definition
R = 0.1;
alpha = 10.4;
beta = 16.5;
rho = -1.16*x(1)+0.041*x(1)^3;
f = [alpha*(x(2)-x(1)-rho)
x(1)-x(2)-x(3)
-beta*x(2)-R*x(3)];
g = [0;1;0];
h = x(1);
C = [1 0 0];
x_dot = f+g*u;
matlabFunction(x_dot,'File','fg_chua','Vars',{[u;x]});
The function is called in a Simulink MatlabFunction block:
fg_chua_sim is defined as:
function x_dot = fg_chua_sim(ux)
x_dot = fg_chua(ux);
end
The execution of the Simulink model fails with:
Error:Function call failed.
Function ' ' (#53.41.52), line 2, column 9:
"fg_chua(ux)"
Launch diagnostic report.
Why is that?

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 8 Avr 2024
Modifié(e) : Fangjun Jiang le 8 Avr 2024
Okay, fg_chua() is generated by matlabFunction(). You need to specify the size of ux in the MATLAB Function block.
Open the MATLAB Function block Editor, click Edit Data, set the size of ux to be 4, based on the diagram.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by