MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
Asked by pouya jamali on 18 Dec 2012

I need to use a structure variable as an input in my matlab function block! I've done the instructions as said in documentation but my model doesn't run. I think structure arrays aren't supported in matlab function block, are they?

Answer by TAB on 18 Dec 2012

Edited by TAB on 18 Dec 2012

Accepted answer

You can create a non-virtual bus signal in simulink and pass this to Matlab function block. Inside matlab function block, bus and its elements can be used in the form of structure.

Similarly you can create a structure in Matlab function block and output it as bus signal from the block.

See

Attach Bus Signals to MATLAB Function Blocks

Create Structures in MATLAB Function Blocks

Can you describe your implementation (post code & attach image). It is hard to say why it is not working without seeing the implementation.

**[Edited 1]**
Type

>> emldemo_bus_struct

in your command window. This will open an example model of bus. You can proceed with this example.

Anyway, which matlab/simulink version are you using ?

Show 3 older comments

pouya jamali on 18 Dec 2012

the *net* is not a signal. It's just a parameter which comes from base workspace!

TAB on 18 Dec 2012

I will, whether structure parameters are directly supported in Matlab function block or not.

**You can not change the parameter value (from any workspace) in the model.
They are constant for the model.**

Answer by pouya jamali on 22 Dec 2012

Yes, structure variables are supported in Matlab function block as input parameters. But You should consider that they can't be changed during the function. they're constants. For doing this first you must define the variable as an input parameter in Ports and Data Manager.
In terms of *str2func* command I don't know whether it's supported or not but the *feval* command works properly.

## 0 Comments