Azzera filtri
Azzera filtri

Saving Simulink variable to Matlab workspace

8 visualizzazioni (ultimi 30 giorni)
Kris
Kris il 4 Giu 2012
Commentato: Kaustubha Govind il 29 Ago 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 Commenti
Ilham Hardy
Ilham Hardy il 4 Giu 2012
Are you using "From workspace" to load the value from the workspace?
Kris
Kris il 4 Giu 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.

Accedi per commentare.

Risposte (1)

Kaustubha Govind
Kaustubha Govind il 5 Giu 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 Commenti
Nancy
Nancy il 28 Ago 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!

Accedi per commentare.

Categorie

Scopri di più su Simulink Environment Customization in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by