Passing a Struct from the workspace to System Block

I am trying to access a struct called "inputs" from the MATLAB workspace while running a system block. When I pass it as an argument to the StepImpl function, it creates a new port in the Block. But I need it to consider "inputs" as a parameter which is accessed from the workspace. This can be done easily in the case of a function block using the Ports and Data Manager and setting the scope of the variable as parameter. Does anyone know how it can be done for a system block ? Is there an equivalent Ports and Data Manager, or is there any other way to access structs from the workspace while running the block ? Any help would be greatly appreciated.

Answers (1)

You can add a non-tunable parameter in the appropriate section at the beginning of the class definition, e.g.
properties(Nontunable)
inputs=0;
end
After saving the file and double-clicking on the Matlab System block in the Simulink model, you get a mask where you can specify a base workspace variable for inputs, which can be struct.

1 Comment

Hello @Oliver Janda, the solution suggested by you worked for me in MATLAB 2019a, however I have to ultimately implement this in MATLAB 2015aSP1, where it throws an error (Invalid setting for the parameter ‘inputs’). Do you know of a way to get the same functionality in 2015a?

Sign in to comment.

Categories

Asked:

on 2 Sep 2020

Commented:

on 18 Jan 2024

Community Treasure Hunt

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

Start Hunting!