Matlab/Simulink: linmod fails for subsystem - matlab

Given a simple Simulink model Model with a single input, a single output and a transfer function in between, I can use linmod('Model') to get the linear state space model. However, when I put the same model into a subsystem called Subsystem under Model and I issue linmod('Model/Subsystem') I get the following error:
Error using dlinmod (line 147)
Subsystem block does not have a parameter named 'SimulationStatus'
Error in linmod (line 59)
[varargout{1:max(1,nargout)}] = dlinmod(model, Ts, varargin{:}, Args);
I am using Matlab/Simulink R2014a. How can this be fixed?

linmod only works for Simulink models, not subsystems. The input and output points for the linearization are those corresponding to Inports and Outports blocks at the top-level of the model.
If you have Simulink Control Design, you should use linearize, which is much more flexible and powerful (or the equivalent linear analysis tool).

Related

Is it possible to convert a Simulink block diagram containing integrator block into TwinCAT?

It is stated that I am trying to convert my control scheme which is implemented in the Simulink into TwinCAT. I have used integrator and derivative blocks in my control scheme.
For testing purposes, I am trying to convert a simple Simulink file containing an integrator block. However, I got a build error. How can I resolve this?
Simulink-block-diagram
Error Picture Simulink during building

Set initial values in simulink idmodel block for an identified process model

I used system identification tool to obtain a state space (order 2) and a process model (2 inputs, 1 output, 2nd order transfer function + delay each) of some data. The models show very nice fit to experimental data in the system identification model output window [Figure 1] but when I use the idmodel block in simulink to simulate the same data it does not look at all like it was on the tool.
I have used exactly the same block diagram with both fitted models. With the state-space fitted model the results are coherent with the system identification tool [Figures 2-3], meanwhile the process model it's totally different [Figures 4-5].
The state-space model only works well with certain experimental conditions, while the process model gives a good fit for all my experiments, that's the reason why I try to use it. The pictures below correspond to only 1 experiment.
I think the problem resides in that I can't set initial conditions to the idmodel block when using a process model instead of a state space model. I can get the initial conditions for the process model using findstates(model, data), but I don't know how to apply them. Any hints on how to set initial conditions for identified transfer function/process models in simulink? Maybe a possible workaround without simulink? I'm open to any solution or ideas.
Thank you.
Figure 1. System identification tool output for both state-space and process model
Figure 2. Simulink output of state-space model
Figure 3. idmodel block with state-space model: initial conditions parameter available
Figure 4. idmodel block with process model: initial conditions parameter NOT available
Figure 5. Simulink output of state-space model
After reaching matlab central and pointing me in the right direction I came up with a solution. Thanks to Rajiv Singh.
I first needed to convert the process model from idproc to idss using idss() instead of ss() -See this article-, then use compare() instead of findstates() to obtain the initial conditions and feed the initial conditions to the idmodel block in simulink. Graphically:
model=idss(T3s_2d);
[y,fit,x0]=compare(run_data_s{8}, model);
%T3s_2d is the identified process model (idproc) from system identification toolbox
%run_data_s is the iddata object with the experimental runs

System Identification in MATLAB

In Matlab I have created a single-output multiple-input fitted model as an idpoly object. This is by using the system identification toolbox and the model is a Box-Jenkins or Transfer Function model. I now want to see what the model does if I put in different inputs (same amount) and no output (model should estimate the output given the input). Yet I did not find a method in Matlab that can do so.
Is there any way I can use an idpoly object (model) in Matlab and use only input to obtain an output? I have tried the command "sim" but it does not do the job.
Use the command "forecast" and specify the input values for the forecast.

Use Sim() command without coder.extrinsic in Matlab

Is there an alternative function to the sim() command oder a direct way executing a Simulink Model / a compiled version of it from Matlab without setting coder.extrinsic?
I want to execute a simulink model inside of an iterative Matlab-function. (Hence, speed matters dramatically). The used Simulink model contains a Dymola interface and hence, I cannot model it directly in Matlab. Another main Simulink model starts and iterates the Matlab functions and hence, simulating it leads the coder trying to compile it efficiently. By setting coder.extrinsic, of course I can use the sim command, but it is way too slow for its purpose. I thought about compiling the Simulink model as an alternative, but do not know if this would be a good approach
The structure looks as follows:
Simulink main model -> matlab functions -> simulink model
sim command needs MATLAB. So you need coder.extrinsic. There is no direct alternate way without coder.extrinsic to simulate a model. You can generate code from the model and call the generate code using coder.ceval functions. But if your goal is only to get more speed instead of getting stand-alone code you can set your model to run in accelerator mode and see whether that improves speed.

RMS not supported in Matlab function inside Simulink

Simulink has a module called "Matlab Function," which allows you to create a custom function in a Simulink flow diagram.
I implemented a simple function in a Simulink Matlab Function module. My function contains a call to Matlab's built-in rms(). When I run the Simulink model, I get the following error:
The function 'rms' not supported for standalone code generation
If I remove rms from my Matlab Function in the Simulink model, the error goes away and the model runs flawlessly.
Questions:
Is there a way to use Matlab's rms in Simulink?
Are there many other native Matlab calls that can't be used inside Simulink?
I just wanted to clarify and expand upon some points made in learnvst's answer.
Even if you are simply trying to simulate a model containing a MATLAB Function block and are not explicitly attempting to perform code generation, you will still get the not supported for standalone code generation error.
As learnvst indicated, there are multiple restrictions on functions that can be used with code generation. However, if you just want to simulate your model, Simulink allows you to do this if you signify these "black-listed" functions as being extrinsic. This lets Simulink know that the functions will be used for simulation purposes only and won't be part of code generation.
In your particular case, add the following line of code somewhere before your call to rms:
coder.extrinsic('rms');
Declaring a function as extrinsic in a MATLAB Function is often useful even when you are performing code generation. For example, you may want to visualize your data using the plot command during simulation, but obviously would not need the plot command to be part of generated code.
Refer to this doc for more info on declaring functions to be extrinsic.
The not supported for standalone code generation part of the error suggests to me that you are trying to use a product like Matlab Coder to make an executable or native code. If this is the case, there are many naive calls that cannot be used directly in both core Matlab and the toolboxes. The coder products only support a subset of the language. More information can be found here . . .
http://www.mathworks.co.uk/products/matlab-coder/description2.html
As for your call to rms, it is only calculating the root of the mean of the squares. Try creating an alternative using something like . . .
sqrt(mean(x.^2))
...where x is the signal.