MATLAB Answers

0

Assign vectors from MATLAB workspace structure to Simulink Model inports

Asked by Masoom Kumar on 28 May 2018
Latest activity Commented on by Masoom Kumar on 29 May 2018
I need help with running a Simulink model with the data from MATLAB workspace contained in structures. Below is a very simplified use-case of what I would like to do
Use Case :
I have a struture in MATLAB workspace called "data", and it has two fields x, and y which are vectors. I have a simulink model with two inports named x and y. I would like to dynamically assign to data from the structure "data" to the Simulink inports and run the model
The above use case is a very simplified scenario. The model that I intend to use can have 100 inports, and thus I do not want to use "From Workspace" block, as it would be impractical for me to add 100s of them
How can I handle such a situation in Simulink. I am a little more than a beginner in MATLAB and Simulink. So, a detailed answer would help me a lot

  0 Comments

Sign in to comment.

Products


Release

R2012b

1 Answer

Answer by TAB
on 28 May 2018
Edited by TAB
on 28 May 2018
 Accepted Answer

You need to arrange your data in time series form.
One of the format is like below:
dataIn.time = [0:10]'; % Depend upon your sample time and stop time
dataIn.signals(1).values = data.x; % x values at each step
dataIn.signals(1).label = 'x'; %Inport name
dataIn.signals(2).values = 'data.y'; % y values at each step
dataIn.signals(2).label = 'y'; %Inport name
Now enter dataIn in Configuration Parameters > Data Import/Export > Load from workspace > Input

  3 Comments

Hello Tabrez
I tried the method that you have suggested and got an error. The details are mentioned below
So, this is what I did
a. Used the script written below to make a dataIn time-series
dataIn.time = [0:10]'; % Depend upon your sample time and stop time data.x = [0:1:10]'; data.y = [0:1:10]'; dataIn.signals(1).values = data.x; % x values at each step dataIn.signals(1).label = 'x'; %Inport name dataIn.signals(2).values = 'data.y'; % y values at each step dataIn.signals(2).label = 'y'; %Inport name
b. Make the changes to Data Import/Export as mentioned (dataIn.png)
c. Executed the simple simulink model (see model.png)
d. Run the model, and I get an error shown below (error.png)
dataIn.signals(2).values = 'data.y';
--> You have assigned string here. Remove the single quote.
Thank you very much for the help. It solved the problem
Just to add, on the page that you had suggested, I found another method using Loading Data Arrays to Root-Level Inputs, which was also very useful. Just bunch all the signals in a matrix :)

Sign in to comment.