Global Variable To Be Used Inside Simulink S-Function
20 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2016-11-5
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 个评论
Walter Roberson
2016-11-7
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!