poeschlorn
poeschlorn

Reputation: 12440

Simulink callback problem

Hey, I have a maybe very simple problem using the PreLoadFcn in my model.

I want my model to load a m-file before starting the simulation (this is what the preloadfcn is for, i think).

So I added in file -> model properties -> callbacks -> PreLoadFcn the line

run('./init.m')

In this file there are several variables set. My Model refers to those variables and throws the exception, that it can't find them when I simply click on "Start simulation". This indicates me, that the callback isn't doing what it should be doing...

The file 'init.m' is in the same directory like the simulation file.

Even trying to add the directory to the matlab PATH didn't take any effect.

greets poeschlorn

Upvotes: 1

Views: 5627

Answers (3)

Harry_108
Harry_108

Reputation: 33

I was also having the same problem. Now it has been solved. the solution was quit simple. after defining the function in the PreLoadFcn* you just need to save the simulink file, and restart it. surely it will work.

greetings, Harry

Upvotes: 0

MikeT
MikeT

Reputation: 1644

You can use Callback tracing to see what callbacks are being called during the process of loading and simulating your model. See the documentation on callbacks for more info.

Also, is init a script or a function? It should be a script, or it should use evalin('base') to put the vars in the base workspace. You can also try putting a breakpoint in init.m to make sure it doesn't get hit.

Upvotes: 1

Edric
Edric

Reputation: 25160

Does it work simply to run "init" at the MATLAB command prompt prior to running the model? If so, you should probably replace the callback with simply

init

which will run the script "init.m".

Upvotes: 1

Related Questions