Can you look at different data files within a Simulink model?

1 visualización (últimos 30 días)
Samantha Szkirpan
Samantha Szkirpan el 7 de Ag. de 2018
Comentada: Sara Nadeau el 9 de Ag. de 2018
I have one Simulink model that can be used for two separate projects whose only difference is the data input to them. My question is: is there a way within one Simulink model to select different data files to read when triggered by the appropriate flag?
For a simplified example, let's say I have a project A and a project B with identical Simulink logic.
The data corresponding to project A (A_data.m) looks something like:
C1 = 100;
C2 = 200;
C3 = 300;
And the data file (B_data.m) for project B looks like:
C1 = 10;
C2 = 20;
C3 = 30;
Is there a way within a single Simulink model to pick between these data files using the project A or project B name plate as a trigger?
I'm thinking something along the lines of possibly a switch block at the top level of the Simulink model that uses project A or B as the switch and runs the corresponding data file. Or if within sub blocks you can assign different, specific data files to each sub block with a switch triggering which sub block to enter, A or B, however I do not know how I could execute either of these ideas.
Thank you for your suggestions.

Respuestas (2)

Fangjun Jiang
Fangjun Jiang el 7 de Ag. de 2018
Use a "Variant Subsystem" block.
https://www.mathworks.com/help/simulink/slref/variantsubsystem.html?s_tid=doc_ta

Sara Nadeau
Sara Nadeau el 7 de Ag. de 2018
Hi Samantha,
Could you tell me more about the data you're trying to load? Is this data for the model workspace or simulation input data (or both?). I think the solution could depend on that.
In terms of using a switch based on the project, I think you could use a startup script. You may be able to set up your project-specific data in the start up script as well. Here's some documentation about how to Automate Startup Tasks for Simulink projects.
Hope this helps!
  2 comentarios
Samantha Szkirpan
Samantha Szkirpan el 7 de Ag. de 2018
I'm not entirely sure which best describes the data I am trying to load, initially I would say it sounds more like model workspace data. Would you mind being a little more specific about what those mean?
As to creating a startup script to execute necessary data files based on a specific name plate, I don't think that would work for my specific case. I would need a solution that will allow me to change name plates after startup on the fly while simulation is running.
With that in mind, do you have any other suggestions?
Thank you.
Sara Nadeau
Sara Nadeau el 9 de Ag. de 2018
What version of MATLAB and Simulink do you have? That will affect how I try to find a solution for you.
If you have 17b or later, you could use the Callback Button block to run a function that modifies the values of your data during simulation. You could also add two Callback Button blocks to your model to specify 'Project A' or 'Project B' and then click the button for the project you want to work on to set the model up appropriately for simulation.
If your version is prior to 17b, I'll have to do a little more research and testing to see if I can help you with a solution. If what you're trying to modify are parameter and variable values that your model uses, I think you may be able to leverage the MATLAB Code option for defining the contents of the model workspace. This topic covers some basics related to the process. The Model workspace is a workspace specific to the model. You can define model variables here, rather than in the MATLAB base workspace to keep your work contained in the Simulink model, when desired.

Iniciar sesión para comentar.

Categorías

Más información sobre Programmatic Model Editing 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!

Translated by