How to run Matlab function inside simulink?
2 次查看(过去 30 天)
显示 更早的评论
I have a written code of motor which works very well in Matlab. I need to connect this code to Simulink and for this, I am using Matlab function block inside SIMULINK.
My code has a sub-function. I need to define some parameters for my sub-function but every time I will get an error.
Any idea?!
I wrote this code inside the Matlab function block:
function y = fcn(u)
global B_bank DLarbr_bank DLbrcr_bank DLarcr_bank DLrarc_bank DLrbrc_bank Rr DLSR Ras Rbs Rcs
load('B_bank.mat');load('DLarbr_bank.mat');load('DLarbr_bank');load('DLbrcr_bank.mat');load('DLarcr_bank.mat');load('DLrarc_bank.mat');load('DLrbrc_bank.mat');load('Rr');load('DLSR');
Va=u(1)
Vb=u(2)
Vc=u(3)
t=u(4)
[result]=ode45('Sub_Func',t,zeros(50,1)); % Maine code
y = result;
The error is :
Global declaration not resolved to a Data Store Memory block registered via the Ports and Data Manager.
Function 'MATLAB Function' (#50.115.121), line 4, column 1:"B_bank" Launch diagnostic report.
Thanks for your help.
0 个评论
回答(2 个)
Walter Roberson
2016-10-30
You need to take extra steps for global data. See https://www.mathworks.com/help/simulink/ug/using-global-data-with-the-matlab-function-block.html
Danilo Teran
2018-12-4
Hi
I am sorry how did you resolve this problem. I am having a similar problem and i didn't find a way to solve it.
Thanks in advance
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!