Use inputs of a user defined Matlab function block as global variables whithin the block

2 views (last 30 days)
In my simulink model there is a Matlab function which consists of many functions:
function block_output = MatFun1(input1, input2, ...)
block_output = MatFun2(x, t)
function y = MatFun2(x, t)
y = f(x, t, input1, input2, ...)
Mathematically MatFun2 is just a function of x and t. Therefore, I would like to keep the notation intact. However, the function requires the block's inputs as well. I tried to globalize the variables input1, input2, ... to be able to use them in MatFun2 as well:
function block_output = MatFun1(input1, input2, ...)
global block_inputs
block_inputs = [input1, input2, ...]
block_output = MatFun2(x, t)
However, I encounter the following error:
Global declaration not resolved to a Data Store Memory block registered via the Ports and Data Manager.
As I mentioned, I do not want to pass input1, input2, ... to MatFun2 as arguments. Moreover, I want these variables to be known just within this block (not the whole simulink model). Nested functions are also not desirable. What options do I have and how can I resolve the problem?
Ali Baradaran
Ali Baradaran on 23 Jun 2017
Edited: Ali Baradaran on 23 Jun 2017
Dear Swarooph,
Thanks for your reply. Since you have commented under my question (instead of answering it), I am not able to vote for it. But thanks again. Regarding your tip, I will reconsider my design.

Sign in to comment.

Accepted Answer

Swarooph on 23 Jun 2017
This documentation shows how to do this: How to Use Data Store Memory Blocks
Specific fix to the question in the comments to the question.

More Answers (0)


Find more on Dependency Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by