FAQ Database Discussion Community

## Sampling time as an input-simulink

I am trying to make a library of functions that will allow me to parameterize filters and other function. In simulink standard blocks, I am only able to set a sampling time prior, rather than take an input. Is there any ideas on how I can create this? My first...

## How can I solve a second order ODE in python when state vector is made of vectors?

I'm trying to "translate" a Simulink model (built to solve a second order ODE and shown in the picture below) into python. inW and inT are vectors of dimensions [1601x2], gains MFW and MFT have dimension [2x1] and gains MC and MK have dimension [2x2]. All initial conditions have been...

## MATLAB and mechanics (physics mostly) [part II]

Resume form part 1 Basic scheme representing the system: We assume that coupling of the two shafts is done with a clutch Equations: • J1*dw1/dt + Td(w12)+Ts(phi12) = T1; • J2*dw2/dt - Td(w12) -Ts(phi12) = T2; where w1 = dphi1/dt, w2 = dphi2/dt, phi12 = phi1 - phi2 w12 =...

## Generate on/off signals of random duration SIMULINK

For my SIMULINK model I need to generate a signal that takes the values 1 or 0. To generate it I need to draw a number from a an exponential distribution and use this number as the time the signal stays in 0. Once this time has passed, I have...

## Clearing Simulink workspace saved with block diagram

I have a Simulink diagram 'abc.slx' developed by a colleague. When I open the diagram, I get a warning: Workspace for block diagram 'abc.slx' was not loaded because an error occurred while loading the MAT-file 'C:\Users\roger\Dropbox\etc\abc.mat' Cannot reload workspace from non-existing data source file: 'C:\Users\roger\Dropbox\etc\abc.mat' It's not surprising it can't...

## function matlab: array initialization for more entity

I need help about a simulink function: I have n entities, in this example only 2. Attribute entity 1: ID = 1 , VALORE = 5 Attribute entity 2: ID = 2 , VALORE = 3 I need to call a function only one time instead of looping and if...

## Sending vector data in the bus

I have a vector data (an array variable for example float32 mydata[5];). for transmitting a single primitve/basic data in a bus its pretty simple. inside_data=Simulink.BusElement; inside_data.Name='somename'; inside_data.SampleTime = -1; inside_data.datatype='single'; this element can be put inside a using Bus=Simulink.Bus; Bus.Elements=inside_data; But this works when the input is a primitive. But...

## Compiling error due to variable size Matrix in simulink (matlab function block)

Looks like multiple people are having trouble with this, none of the workarounds worked for me though. I am using Matlab 2014b with Simulink 8.4. I am solving a DAE system that describes a turbocharged engine. The system consists of 4 equations, 2 of them are DAEs, 2 are ODEs....

In simulink, when you clone a subsystem, after a while, you need to update them. The problem is that when you update a subsystem, the cloned one is not updated as well. Is there any way to synchronize the cloned subsystem in a way that when you change each of...

## Graphic object handle array in embedded matlab function in Simulink in R2014a or newer

For debugging, I have some plots of vectors in an embedded matlab function in Simulink. Up to Matlab R2013b, everything works just fine with the following minimum example code: function fcn %#minimum example for plot within for-loop of embedded matlab function coder.extrinsic('delete'); coder.extrinsic('quiver'); coder.extrinsic('gobjects'); numSteps=4; persistent hFig; persistent hVector; if...

I am running a simulink model in external simulation mode and am having the following problem: When I stop the simulation and get the data from the scope, it never saves more than the last 5,000 data points. I have tried unchecking "Limit data points to last:" checkbox, but that...

## Test for compatibility in Matlab

I'm working with an open source Matlab toolbox which, according to its creators, is compatible for versions of Matlab over 7.6, i.e., R2008a. I tried to run it in R2011b and it threw the exception: Undefined variable "Simulink" or class "Simulink.Mask.create" Since: 1- Simulink is installed and functional in this...

## How to set Sample time for all components within a subsystem?

I have a subsystem I am trying to make, and within this subsystem is a discrete filter block. I am trying to place a mask over the subsystem, and have it so the dialog will set the sampling rate of the discrete filter block. Is this possible and how? The...

## Simulink - Finding index of vector element where accumulation crosses a threshold

I'm looking to improve the delay estimation portion of a Simulink model. The input is an estimated impulse response for the system. I want the index of the first sample of the impulse response where the sum of the absolute values of it and the previous elements exceeeds a certain...

## How can i save previous value of variable in Matlab Function

Hello I would like to know how to save the previous value of an output variable in a matlab function. function y = fcn(x,d,yp) yp=0; %here I want to initialize this value just at the start of simulation if (x-yp<=d) y=x; else y=yp + d; end yp=y; % here i...

## MATLAB event location to find time required for full conversion of different species

I have a system of ODEs as follows: dx1/dt = (x1,x2,x3) dx2/dt = (x1,x2,x3) dx3/dt = (x1,x2,x3) The initial conditions are x1=x2=x3=0 @ t=0 and the constraints are dx1/dt = 0, dx2/dt = 0, dx3/dt = 0 for x1 = 1, x2 = 1, x3 = 1 respectively. Once x1,...

## Putting sampled values into a matrix- simulink

How can I put values into a matrix in simulink? For example, if I sampled a sine wave every 0.5s, and put that value into a fixed size matrix of size N. After the matrix is full, it would overwrite the oldest values.

## 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...

## Matlab and mechanics (mostly physics)

I am trying to solve a mechanics problem regarding momentum of two shafts. I have never had a class an mechanics before, so i don't know how to approach this problem. Given: equations: • J1*dw1/dt + Td(w12)+Ts(phi12) = T1; • J2*dw2/dt - Td(w12) -Ts(phi12) = T2; where w1 = dphi1/dt,...

## Solving ODE with Simulink in Matlab

I need to solve this ODE using Simulink and I don't know how to make it. I only know how to do it using ODE solvers. y'' - y' - 2y = e^(3x) y(0)=1, y'(0)=2. I rewrote the equation obtaining an ODEs: y' = f(x,y) y(x0) = y0 y'1 =...

## error due to the configuration of the solver “fixed-step”

I tried my whole Simulink model with the configuration which are mentioned in the answer of my previous question by am304.But, an error concerning the fixed step size appears to me. Unfortunately, I couldn’t understand what it means: The computed fixed step size (2.195764022074938e-011) is 1000000 times smaller than all...

## How can I use C generated code from Simulink into a MATLAB script

Here is my problem: We would like to use our different Simulink models within a script in a much faster way than having to open the Simulink environment (our MATLAB script using Simulink is launched many time). For that purpose, I want to transform the Simulink model into a C...

## Including libraries in the custom code section in Simulink

I'm trying to Include some Libraries, like metis in the custom code library section in Simulink. Do you know what type of libraries Simulink excepts? Must they have the ending .a, .o, .dll or lib? And can I include them into my custom c code with #include <metis.h>?

## Reproducing a discrete filter block in simulink

I would like to make a discrete filter, where the sampling rate can be controlled by an input. I am trying to understand how the discrete filter block looks, "under its own mask." Is there anyway to retrieve the code behind this block so it can be modified for my...

## How to import arrays of data into Simulink

I want to import several arrays of data into Simulink so that I can cycle through each of those arrays, operating on one column at a time, and choosing a different array at random intervals. (So let's say I start cycling through the columns of array 1 for 1 second,...

## How to Add external frequency inputs in the analog filter design block simulink in matlab

I want to be able to externally have inputs for the lower passband edge frequency and higher passband edge frequencies for the butterworth filter block in the simulink signal processing toolbox in matlab. How can I achieve this. Currently you'll have to click the block to specify these frequencies and...

## tfest :: too many parameters for chosen data size

I am trying to find transfer function for some input data and output data using the code Temperature = [zeros(1,153) 300*ones(1,47)]; out_temp = [zeros(1,147) ScopeData4.signals(1).values']; N = 1; tfdata_tem = iddata(out_temp,Temperature,0.001); sys = tfest(tfdata_tem,N); but in the end I get the following error despite the fact that i have increased...

## How to pass a Matrix in Simulink using S-Function

I have written a S-Function in MATLAB. Now I want to pass a Matrix into the input via the 'simin' Source. I have initialized the time of the simin variable with simin.time = 0 and the values are stored in a dynamically sized matrix. So for example simin.signals.values = ones(4)....

## How to access variables in the properties block of a Matlab System Object?

I am working on a simple System Object in Matlab/Simulink. It looks like this : classdef realtime_header_detectorSO < matlab.System & matlab.system.mixin.Propagates % correlateHeader % % This template includes the minimum set of functions required % to define a System object with discrete state. properties Header %nrOfBitsInPreviousStep=0; s=100; d=zeros(1,s); end properties...