cansim
cansim

Reputation: 3

FOR iterator block in Simulink and model's input

Hello I'm building a exe from a simulink model and in order to do that I pass the inputs to it through a .mat file.

enter image description here

My question is, since in my model is present a "for each" block, how can I store the data in the .mat file? Normally (without the for each block) I would store the input as a constant vector in the workspace (see the upper part of the simulink model) and it will handle automatically how to pass the data during the simulation time. But in my case, since I want to export as .exe and pass the input programmatically, I need the input as .mat file and the presence of the "for each" block screw up the building the vector time (since is unclear how to combine time vector with data vector inside the .mat file because is unclear to simulink which data take at a given simulation time.

Thank you for any help!

Upvotes: 0

Views: 703

Answers (1)

Phil Goddard
Phil Goddard

Reputation: 10772

It's not really clear what the specific problem you are having is.

In your upper diagram, the model will run when you have a variable

>> input = 1:3;

If you turn on Display->Signals & Ports->Signal Dimensions then you'll see that the signal coming out of the Constant block has a dimension of 3.

For the lower diagram, create a variable in MATLAB, that since it will be used in a From File block, must adhere to the specifications required for that block, which means the first row is a time vector, so

>> t = [0 10]
t =
     0    10
>> u = [1 1;2 2;3 3]
u =
     1     1
     2     2
     3     3
>> tu = [t;u]
tu =
     0    10
     1     1
     2     2
     3     3

And then save this variable to your file,

>> save input tu

Now the signal coming out of the From File block will also be of dimension 3.

Change the values of t and u to suit your specific problem.

Upvotes: 0

Related Questions