0

I would like my Simulink Level 2 S function to sequentially run a series of test cases. Each test case populates a struct containing multiple numerical arrays. I am currently trying to achieve the above in two steps:

  • Step 1: generate test cases using a M file, save to Workspace as an array of structs
  • Step 2: read the array of structs from the Workspace into my model, using a Level 2 M file S function to process the test cases.

Step 2 is problematic for me, in that I cannot figure out a way to get the S-function block to accept the array-of-structs variable from the Workspace as input. I want to try avoiding the simin method (another Stackoverflow discussion, here), because it seems to require representing the entire structure as a single data column, and I would like to keep the struct intact. Also tried using a Constant block with the struct array as the variable name, but that returns an 'Invalid setting for blockname parameter Value' for the block.

Would appreciate any suggestions for getting this set up correctly. Also open to a different method of building the model, if absolutely necessary. Thanks!

EDIT: Realized that I can import the data within the S function M file itself, using load. This works for the purposes of my project. However, am still interested in knowing whether a conventional solution exists for this.

Community
  • 1
  • 1
npn
  • 1
  • 3

1 Answers1

1

If you just want to access the workspace, I would consider using evalin(caller,'expression') inside you M-file S-function:

mystruct = evalin('base','MyStructFromWorkspace');
/* (process mystruct) */

It should also do the trick.