Error "Undefined function or variable" when starting Simulink

2 Ansichten (letzte 30 Tage)
Simon Mürwald
Simon Mürwald am 2 Feb. 2017
Kommentiert: Walter Roberson am 6 Feb. 2017
Hello,
I'm currently using R2012b and get an error "Undefined function or variable 'delta_t'." when my function starts a Simulink Model (The Model was not made by me).
When I set a Breakpoint a this part of the function:
simout = sim(sim_pathfile,'SrcWorkspace','current');
I see the workspace of the function and there is a 1x1double variable called "delta_t" and the Base Workspace is empty. In this case I get the error "Undefined function or variable 'delta_t'."
If I define a variable "delta_t" in the Command Window before starting the function (so there is a variable "delta_t" in the Base Workspace), the Simulation starts and works fine. In this case, there are all the relevant variables in the function workspace and only the "delta_t" variable is in the function and the Base workspace.
So far it looks like the simulation uses the function workspace, as I defined it with:
...,'SrcWorkspace','current');
And only for the delta_t variable it uses the Base workspace.
Now the part, where I stopped understanding anything:
I started to set the variable "delta_t" with various values in the function workspace (the variable "delta_t" in the Base workspace stays the same) when I looked at the results of the simulation, I saw that the simulation uses the value of the "delta_t" variable in the function workspace.
Could it be that the Simulink Model looks at the Base workspace if the variable "delta_t" is there (I do not understand why it does this only for this one variable and non of the others, it is using) and then uses the "delta_t" variable of the function workspace?
I hope it was understandable and I am not doing some really stupid mistake.
Thank you in advance
  2 Kommentare
Nirja Mehta
Nirja Mehta am 6 Feb. 2017
What do you mean by "function"? Is it a MATLAB function block in your Simulink model? I have attached a simple model of my understanding of your description.
"delta_t" is defined in "fcn" function.
Correct me if I am wrong or attach your model files.
Walter Roberson
Walter Roberson am 6 Feb. 2017
When you use a From Workspace block, then Simulink should look in the workspace of the function block that called sim() if the model was started that way, and would look in the base workspace if the model is started from a menu action or Function Key.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by