Simulink Set sample time the same as Data - matlab

I am trying to make a simulation in Simulink, with the fuzzy model.
As inputs, I have set four time series variables from the workspace (compatible to simulink after performing Simulink.Timeseries function): every row of the variables has a linked time starting from 0 to 10566 (seconds, I believe). How can I set the sample time in simulink source block in order to pick every exact case without interpolation?
Thank you for your kind answers,
Phalaen

Are you using the From Workspace block? If so, it's simply a matter of specifying the sample time in the block parameters and unticking "Interpolate data". You can also display the sample time information of the model to check which sample time each block is using, see View Sample Time Information in the documentation.

Related

Setting a Matlab function block's sample time in Simulink

Is it possible to explicitly set the sample time of a Matlab function block in a Simulink model? If yes, how? If not, how can you change the sample time of a signal coming from a Matlab function block?
For instance, how can one make sure that the sample time of a (possibly variable-sized) signal coming out of a block will be discrete?
Your best option is to use the Rate Transition block.
Also have a look at the Convert Signals Between Continuous Time and Discrete Time example to see how it's being used in practice.
Using the Matlab Function block you can Right click > Block Parameters > Sample time. Change from -1 to the sample time you want.
To make sure your simulation is using the correct sample time you can select the double arrows in the left panel and click on "Colors". Then, back in the double arrows, select "Sample Time Legend". Now, the different colors represents different rates in which Simulink is running.

How do I create monte carlo results on a graph using parameter variation experiment on anylogic?

I am working on the evacuation time of pedestrians by running 100 runs using monte carlo. I have trouble creating the graphs and am very confused in the steps. Something is missing and I am not sure what it is.
I have created a parameter variation experiment page and included a Histogram2D data and a graph from analysis but I don't know how to read the data I want from the main.
Below image is the data I am trying to acquire from the timeMeasureEnd which isn't linked yet.
I use the code
root.timeEnd
but get this error as shown below
You can directly access the timeMeasureEnd's internal dataset: timeMeasureEnd.dataset. See the AnyLogic example model Measuring Length of Stay, referenced in the documentation.
As for your error, your statement gets interpreted as a variable declaration. As soon as you put some useful code in there it works, eg. a simple assignment to a local dataset in your Experiment class:
dataset = root.timeMeasureEnd.dataset;
To save the longest measured time after each run:
add a dataset, deactivate update automatically
add a integer variable iteration to save the current iteration index
use the following in After Simulation run code:
iteration++;
dataset.add(iteration,root.timeMeasureEnd.dataset.getYMax());

Debugging Simulink model programmatically

I have written a matlab program for a simulink model and taking control through it programmatically, but I am facing one problem while using set_param('testmodel11', 'SimulationCommand', 'start');.
It gives all the values at once, that is gives the entire scope and workplace values all at the same time, but I don't want this. I would like to run the program and execute at that point, seeing only rest of the values should be zero. How can I stop the simulation at that point and fetch plots and values from that point only, the rest should be zero. And ideally have this same behavior for the next break points too?
There is a way to pause the simulation at certain breakpoints (simulation points), plot the output or do whatever is desired of it, and then continue the simulation until the next breakpoint.
However, at any breakpoint, you will get output data from all the time samples till the breakpoint is reached. To isolate data from a certain timestamp, you can calculate its index based on the sample time and extract it from the workspace (output data is stored as an array)
Here is the link to my answer which will be helpful, pls go through it:
https://stackoverflow.com/a/38348315/6580313
Now, in the m-file which you will run when the simulation is paused, you can change the value of the constant block which specifies the next simulation time at which simulation needs to be paused. In the m-file, you can also write a code snippet to access the output data.
Once the simulation continues, it will be paused at the new simulation time specified in the constant block.
Let me know in case you have any queries.
It sounds like you want to use the Simulink Debugger. Check out the documentation for more details on how to use it. The main command-line interface to it is sldebug.

import a continuous bitsream from workspace into simulink using "In" block and then buffer it using "buffer" block

how to import a bitsream form binary vector from workspace into simulink.Actually I have found that I can use simin block or In block but my binary vector is independant of time. I tried to use Const block and it works but afer that when I wanted to put my output in the Buffer block in simulink, it didn't work because the input is continuous and not discrete. So I am asking if it's a way to add time to my binary uni-dimensional without having any influence on the result?and how can I do it?
Or is there another way to import this date to avoid this problem with Buffer block?
Your screenshot shows your constant block to have a sample time of Inf. As the error message suggest, you need to change that to a discrete sample time. In addition, you should also:
check your model is using a fixed-step solver
check what time step you are using for your chosen fixed-step solver (ideally the same as your constant).
You can have multi-rate models, but you need to manage the rate transitions with Rate Transition blocks. For more details on sample times, see the documentation, in particular how to view sample time information in a Simulink model. You should probably also have a quick look at the Choose a Solver section.

Simulink From Workspace: can't use timestamps from matrix

I'm using the simulink block From Workspace to read in some audio data provided by a script. I have formatted the data in a matrix with 2 columns, the first is the timestamp and the second is the data.
In the configuration paramaters, I have specified Fixed-Step and Discrete solver. The Start time and Stop also need to be configured manually and don't seem to come from the data.
Also, in the From Workspace block configuration, I need to specify the sample time (1/44100) or I get a warning if I specify -1, to inherit from the data and then get strange sample times.
So, how can I get simulink to use only the sample times in the matrix and use the first and last timestamps as the start and stop time of the simulation?
You should be able to do what you want by doing the following:
Firstly note that your problem is by definition not fixed step, hence you cannot use a fixed-step solver, which by definition is ... fixed-step.
You must use a variable step solver.
Assuming your (2 column) input data is called simin then set the start and stop times to be simin(1,1) and simin(end,1) respectively.
In your From Workspace block set the sample time to be 0 (which should have been the default).
Also de-select the Interpolate data option; and set "Form the output after final data value by:" to zero (you won't be using anything past the end of your data set so this should be OK.
Then you need to tell the solver to take additional steps to those that it would naturally want to take.
Do this on the Data Import/Export pane of the Model Configuration Parameters.
Near the bottom of the pane there is a selection box and an edit box for doing this.
Note however that this does not prevent the solver from taking steps at other time points, it just forces it to take additional steps at the times you specify.
But because you have your From WOrkspace block to not interpolate this shouldn't be a problem either. You should put simin(:,1) in here so that the solver is guaranteed to take steps at the time points in your input data.
Note that if you want an input block that only samples at the time points in the simin time vector then the only way to do this is to write an S-function that uses the mdlGetTimeOfNextVarHit method to tell the solver what the next sample time (for this block) should be.