Can you access a Data Store variable in a MATLAB function WITHOUT having it as a function input?
Ältere Kommentare anzeigen
I have a system in Simulink that uses a ton of global variables that I set up using Data Store Memory blocks, and with that I have subsystems that contain MATLAB functions that are called. One function, for example, increments a variable at the end of each run. I have this variable defined and used elsewhere in the simulation, and I don't want this function to have any input arguments. How can I access the variable in this way?

To visualize, I have my function called in my simulation, and inside this function I would like to manipulate IncTest WITHOUT having this funciton returning anything or taking any input arguments.
% Ideally I could do something like:
% extern int IncTest;
function TestFunction()
% Function
% .
% .
% .
IncTest = IncTest + 1; % Done at the end of function
end
When it comes to a counter like this, I know there are workarounds I can do, such as build this function using Simulink blocks instead of the MATLAB function block, or increment it when the operation is complete outside the function. The obvious solution is to just set it as an input argument, but I would rather not for specific cases that use a good handful of all the variables, and when I am trying to keep this simulation as close to my original project as possible (A project already coded and implimented). The problem is that I have other cases where these options and workarounds wouldn't apply, so I was wondering how I can get my Data Store variable into the MATLAB function like this.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Simulink Functions finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!