Simulink outputs variables but they are not being sent to the workspace.
110 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Michael Colantonio
el 2 de Abr. de 2019
Respondida: Reid Spence
el 26 de Jul. de 2024
While using my PC at home I am using 'to workspace' blocks in my diagram with save format array. When I run the simulation i get the following the the command window:
ans =
Simulink.SimulationOutput:
Vin: [2002x1 double]
Vout: [2002x1 double]
t: [2002x1 double]
tout: [2002x1 double]
SimulationMetadata: [1x1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char]
Undefined function or variable 't'.
Error in P1_2 (line 79)
plot(t,Vin,t,Vout)
It seems to me that simulink is outputting the variables but they are not appearing in the workspace and therefore it thinks they are undefined. I tried running the simulation on a computer at my university and it worked. I tried reinstalling Matlab on my home PC and it still doesnt work. Version 2019.
0 comentarios
Respuesta aceptada
David Avila
el 21 de Dic. de 2019
Editada: David Avila
el 21 de Dic. de 2019
If you are running 2019a, the Simulink default settings for the "To Workspace" block have been changed and would need to be set back from being a single simulation output:
I have to do this every time I make a new model till further notice
Edit: Grammar
26 comentarios
Khaled Hassan
el 22 de En. de 2023
Thank you very much, I was loosing my mind. This was very helpful
Más respuestas (3)
Rostislav Teryaev
el 2 de Abr. de 2019
First of all, you have to assign a structure Simulink.SimulationOutput to some variable
temp = Simulink.SimulationOutput;
Next, you need to access field t or Vin of this structure
temp.t
temp.Vin
To use plot you want this
temp = Simulink.SimulationOutput;
plot(temp.t, temp.Vin, temp.t, temp.Vout)
1 comentario
Reid Spence
el 26 de Jul. de 2024
By default, when you simulate a model, simulation results (including To Workspace blocks) are returned as a single Simulink.SimulationOutput object.
You could disable this behavior with the "ReturnWorkspaceOutputs" parameter of models, however I would recommend against it as the SimulationOutput object has several advantages over returning To Workspace values as their own variables:
- Metadata: The SimulationOutput object stores helpful metadata about a simulation, such as warning, errors, timings, etc. It can be very helpful to refer to these to understand a simulation, especially if some time has passed between when you ran the simualtion and when you are reviewing the results. Access metadata of simulation runs - MATLAB (mathworks.com)
- Differntiate from other results: The SimulationOutput object acts a helpful container of all results related to one simulation. That container allows you to easily know which outputs and metadata are associated from the same simulation and more easily differentiate them from other simulations you may have run. This avoids confusion and mixing up results from previous simulations.
- Support for changing workflows: The SimulationOutput object provides better support for switching between serial simulation, parallel and batch simulations, and deployed simulations. When you return results as a single simulation output, the syntax to simulate a model programmatically is the same for the sim, parsim, and batchsim functions.
- Object methods: Calling plot() on the SimulationOutput object will open up Simulation Data Inspector. >>plot(out)
0 comentarios
Ver también
Categorías
Más información sobre Simulink Functions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!