multiple step function for a single flow system - simulink

For Matlab simulink, how does one go about generating multiple step function at different conditions for a system
I am trying to simulate a simple flow through a tank and controlling the temperature within. At various interval say time at 10ses and 20secs i intend to draw out different flowrate/flow amount of water.
With the system designed, how do I show on a single scope how Flow in changes with the different amount of flow out drawn.
Appreciate any kind advises

There are many different ways of doing this, for example defining the data in MATLAB and using a From Workspace block or using multiple Step blocks summed together appropriately. But to start I'd suggest you look at the Signal Builder block.
To view multiple signals at once in the same Scope, either set the scope up to have multiple inports, or Mux the signals together and feed them in in the usual way.

Related

integrate Modelica variable without influencing state selection

I want to integrate a Modelica variable over time, just for convenience in plotting and post-processing. The variable I want to integrate over time is the power of a compressor so that I get the total energy. The first idea would be to add these lines:
Modelica.Units.SI.Power P_comp;
Modelica.Units.SI.Energy E_comp;
equation
P_comp = der(E_comp);
Is that the recommended way, or are there (better?) alternatives? Is it expected to influence the selection of dynamic states?
Assuming that those two lines are the only ones using E_comp that should work.
Basically E_comp will be part of its own separate state-selection block and changes there shouldn't influence anything else.
However, state selection consists of a number of algorithms and heuristics so it is difficult to formally guarantee that any change does not influence it.
I could imagine some strange possibilities that would break this, but I don't think anyone has implemented them - and I don't see a use-case for them (except to mess up cases like this).
And if you instead of integrating want to differentiate a signal it is a lot messier.

I want to run two or more simulink model in parallel and synchronisation.

Hi I want to run two or more simulink model in parallel and synchronisation. is there any way to do it? One way I think is by creating a subsystem and put all models inside it. It should run parallely. This one is not prefered for me. I want to open two matlab instances and run two different model in synchronisation. is this possible? I want to do it programmatically. Any help is appreciable.
You should use a matlab script and implement the synchronization logic in it.
== Update ==
You can execute the simulink model by simply calling it from a Matlab Script.
You have to define a task containing the next steps: First you can calculate inputs in Matlab. Then execute the first model with the first inputs. Then save the results to a certain variable. Finally use that variable on the second model and launch second model simulation.
Repeat the task for all the necessary steps.
If you have the Instrument Control Toolbox, you can send/receive data between the two models via TCP/IP or UDP/IP blocks. No need to have two MATLAB sessions, this can be done from one MATLAB session, see this loopback example.
However, I would query the need to have two separate models. Why not put both models in the same model as subsystems, or even as Model blocks if you want to keep the atomic nature of each sub-model?
The best way to run parallel simulink simulations is probably the parsim command. Their is a complete article on the Mathworks website explaining how to do it:
Run Parallel Simulations

Any Tic Toc function in Simulink for embedded blocks

I have a system with some embedded Matlab blocks where I'd like to perform some actions after a certain amount of time, in this case turn on lights and switches in an interface to which I send signals from Simulink.
The problem is that I thought I'd use "tic"-"toc" and "while" in a Matlab function block to perform these actions, say one parameter becoming 1 after 5 seconds, the following parameter becoming 1 after 12 seconds and so on, but I noticed that tic-toc apparently doesn't work in Simulink for embedded functions.
Is there any similar functions that could be used in Simulink for embedded functions or is there any other way to do this?
Edit: I've tried to get the clock's time as well, but it's a growing value. Is there any way to "lock" the time as a parameter when the block's function is executed?
You shouldn't be using absolute time in an embedded system, which is at least one of the reasons why tic-toc and clock from MATLAB don't work with Simulink Coder.
You should create your own counter, which you start and stop when you need to.
This is pretty easy to do using a Unit Delay and Summation block.
If you need to be able to enable and/or reset the counter then use the appropriate block from the Additional Discrete library.

How to introduce delay(waiting loop) in simulink between two independent models

I am having a model in simulink consisting of two parts one of image processing and other of control systems. I want to introduce delay(waiting loop) between the two independent models i.e when image processing part and controller part is simulated once I want to introduce some delay before the second simulation.How can I do this? any help???
you can put between them a Delay block z^-1 specifiing the delay or create a stateflow block with your logic and delays.
note: there are olso a delay for continus function, see what fit best for you

is there a way in Simulink to use the same set of blocks on multiple signals (without copying those blocks)?

I am implementing some head tracking and I get 2 matrices of horizontal velocities. (A vector field decomposed into vertical and horizontal velocities). For each of these matrices I do some math to calculate the actual head tracking.
My question is, is there a way to do that math (which is a set of blocks) on both matrices without copying the math blocks onto each signal?
It's hard to explain so here's a screen shot of my model:
You can see that the "complex to real-imag" block has 2 outputs (this is the little one in the middle). The mean block and the integrator circuit then calculate the head velocity and position for the real matrix (horizontal position). I want to do exactly the same routine on the imaginary matrix (vertical direction). Obviously I can just copy the blocks, but surely there must be a better way of doing it? In a way I'm looking for an analogue of a loop in "normal programming" like C or something, where a block of code is executed several times on different inputs.
You can create a Library in Simulink that contains code you can reference multiple times.
Go to File -> New -> Library. In the model window that opens, you can create any number of subsystems with whatever code you want. Then, just drag a subsystem from the library into your model. The subsystem will now appear in your model with a little arrow icon in the lower left. This indicates that the subsystem in the model is a link. You can drag as many instances of the library subsystem into your model as you wish, just as you can call a function as many times as you wish in any other programming language.
If you right-click on the subsystem in your model, you can select "Link Options -> Go To Library Block" to get back to the library. You can make changes in your model and propogate them back to the library as well.
One way to easily reuse a set of blocks is to create a subsystem out of them. In your case, you can create a subsystem by grouping existing blocks, then simply copy and paste your subsystem to use it for your imaginary output.
Although potentially more complicated, you could also look into using mux signals to avoid having to copy parts of your model.