Global Variable To Be Used Inside Simulink S-Function
18 views (last 30 days)
Show older comments
Hello,
I am trying to understand how to leverage a global variable to hold a string that is to be used in an S-function as soon as my model is ran. Basically, I want to be able to run things in batches down the road, and one of the things that needs to happen in my simulink model is that a user provides a file name 'foo.txt' to draw data from and a destination file name where data is streamed out to such as 'bar.txt'.
These values are to be set once before the sim runs. In my workspace I declared a global variable called input_file and set that to 'foo.txt'. When I run the simulink model with a breakpoint at the point in the DoPostPropSetup function where I perform a task involving the global variable, I expected to see it in the workspace for that function. That was not the case. I even declared global input_file right before the breakpoint and it did not appear in my workspace, much less carry the value I wanted.
I also tried using the "constant" block to carry the input file name, but what I found was that I can't use a string for that, (okay, so convert it using uint8(input_file)), and much worse, if I set up an input with the length of the file name hard coded (not desirable) as the dimension of the InputPort and then use a breakpoint in the S-function block I've made, the value for the InputPort is simply ' ' (two single quotes; an empty value). Do I have to wait until Simulink samples this input?! I need the filename at t=0 to begin the sim, not t = length(input_file)/Fs.
Is there a way to do what I want here? I need the user of my simulink model to be able to set an input and output file name which is to be used in a part of an S-function that acts on that string. Setting globals up in the workspace doesn't seem to work, and if I can't get the whole array into the S-function at t=0 to be acted on using a "constant" block, then I'm stuck.
Thank you in advance for your advice!
0 Comments
Answers (1)
Walter Roberson
on 5 Nov 2016
Are you using a Data Store Memory block? https://www.mathworks.com/help/simulink/ug/using-global-data-with-the-matlab-function-block.html
3 Comments
Walter Roberson
on 7 Nov 2016
When I was searching the other day I was not sure if such registry blocks would be appropriate for S functions or if they only applied to MATLAB Function Blocks
See Also
Categories
Find more on Model, Block, and Port Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!