[Matlab] function using Sim() to call Simulink model error

Matlab basics:
1. The knowledge involved here is the workspace. The function uses the Caller workspace. The Base Workspace used with Command Windows is not a workspace. It is opened before the function enters execution, and is released when the function call ends.
2. In addition to declaring global variables (many users recommend not to declare global variables), you can also use the assignin function, the specific method: assignin (ws, 'var', val) ,

"This MATLAB function assigns the value val to the variable var in the workspace ws. The var input must be just an array name and cannot contain an array index. If var is not present in the specified workspace, assignin will be created. ws can contain 'base' Or the value of 'caller' to represent the workspace of the MATLAB base workspace or caller function." (Official Document)

3. The post said that sim can also use the local workspace, such as

function the_best_function()
...
options = simset('SrcWorkspace', 'current');
sim(modelname, [], options)
...
end

A newer version can be used directly

sim(modelname, ‘SrcWorkspace’, ‘current’)

But note that this method cannot be used with the PCT (Parallel Computing Toolbox).

At present, my problem has not been solved. I will do this first.

Intelligent Recommendation

Matlab Function in Simulink

Add MATLAB FUNCTION, double-click to open the input function in matlab Click Edit Data. Set to Single Type, Apply   SIMULINK is changed to SINGLE Join Display components After running, the result...

Create Matlab Function in Simulink

Open Simulink, use library browser in Blank Model, and search for Matlab Function. Select the FCN module and drag to the Simulink interface. Double -click the editing function, like: function x=freebo...

Using matlab / simulink bode FIG drawing, and a drawing origin arctangent function

This is firstly a filter circuit Below is a set of specific parameters of the low pass filter Then guidance cut-off frequency of the filter circuit of the formula Then use matlab / simulink can plot t...

Call between MATLAB \ Simulink and python

Matlab-Python calling each other PythonIs more and more widely used, and has great advantages in deep learning, machine learning, data mining, etc., and python is open source and has a powerful third-...

Matlab / Simulink: Joint Simulation in Simulink Call PSO in SIMULINK

PSO module call in matlab / simulink via s-function Many combined simulations need to call PSOs and to implement PSO calls in user-defined functions in user custom functions in Simuli / NK. Call the M...

More Recommendation

Matlab script creation Simulink model

This article introduces how to create the Simulink model automatically with the Simulink script. First list some of the functions used: For the specific effects, see the following example The model of...

The usage of the MATLAB SIM function and the SimSet function

The SIM function is used to run the Simulink model. It should be noted that users cannot control their simulation process (such as pause and continuing), and once it runs, it will reach the end of the...

Matlab simulink save error problem

I used simulink to build a simulation diagram today, but it always reminds me when I save it at the end the model contains the characters that cannot be encoded with the model’s character encodi...

MATLAB SIMULINK report error notes

Error 1. Please change your current directory to a writable directory outside of the MATLAB installation area. Tip directory needs to be changed Current Folder with M filePath changeUnder the folder c...

MATLAB / Simulink function S given in

S function on MATLAB / Simulink is given: Output returned by S-function 'xxx' in 'xxx' during flag = 3 call must be a real vector of length x S function is frequently used during system simulation, it...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top