How to run Matlab function inside simulink?

3 Ansichten (letzte 30 Tage)
Babak
Babak am 30 Okt. 2016
Beantwortet: Danilo Teran am 4 Dez. 2018
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.

Antworten (2)

Walter Roberson
Walter Roberson am 30 Okt. 2016
  1 Kommentar
Babak
Babak am 1 Nov. 2016
Bearbeitet: Babak am 1 Nov. 2016
Thank you, Walter, for the link. I spent one day to figure it out but still get an error. I made a one minute video about the procedure. I appreciate if you have a look and let me know what is wrong. ( Apologies in advance for trademark) https://www.youtube.com/watch?v=RAnTjvzRdcY
Error is: "Variable 'B_bank' is resolved in the workspace ('base') for block 'test1/MATLAB Function' but it is not a 'Simulink.Signal' object."
Some explanation about my code: I have 9 matrixes with different sizes which I need to make them global.
The function (sys_FINAL) inside the MATLAB Function, calls these matrixes.

Melden Sie sich an, um zu kommentieren.


Danilo Teran
Danilo Teran am 4 Dez. 2018
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

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by