Saving Simulink variable to Matlab workspace

28 views (last 30 days)
Kris
Kris on 4 Jun 2012
Commented: Kaustubha Govind on 29 Aug 2014
Hello,
With the 'to workspace' block i want to write values to the matlab workspace. I load in a value from workspace (from an array i extruded from excel). Each step i want to save this value that i take from the workspace to the variabel A:
So if it at step 1 in the array the value is 4. I want to write this value of 4 to the variabel A. At step to the value is 10, so i want the 4 to be replace by 10.
While doing this i experience the following problems.
The first few steps (4 steps) the variabel a just keeps the value 0 (i set the ammount of date to save to 1 instead of inf as i only need one value). Sometimes i get the correct value. Sometimes i get the value of the step before.
What am i doing wrong?
Kind regards,
Kris
  2 Comments
Ilham Hardy
Ilham Hardy on 4 Jun 2012
Are you using "From workspace" to load the value from the workspace?
Kris
Kris on 4 Jun 2012
Yes. I opened excel in my matlab workspace. Next i put my data into an array. And at last i imported my data into Simulink workspace by the From workspace block.

Sign in to comment.

Answers (1)

Kaustubha Govind
Kaustubha Govind on 5 Jun 2012
AFAIK, the "To Workspace" block logs the signal at each time-step. At the end of simulation, there is an array/structure with signal values as well as the time-stamps corresponding to each value. It's not clear to me how you log a single scalar value using this block.
Also, note that you cannot expect the "To Workspace" block to update the workspace immediately (during simulation). It is only guaranteed that the variable will be ready in the workspace at the end of simulation. Please see the second paragraph of my answer here about why I think this guarantee doesn't exist.
In general, you need to follow the technique in this section for what you require: Accessing Block Data During Simulation.
  2 Comments
Nancy
Nancy on 28 Aug 2014
The link "Accessing Block Data During Simulation" is broken--perhaps going back to an older version of Simulink. Do you what would be the corresponding section in the R2014a documentation? I can't find a section with that title, and it sounds like it could be relevant to my problem. Thanks!

Sign in to comment.

Categories

Find more on Simulink Environment Customization in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!