1
votes

I want to have a ui button that will start and pause a simulation. The script I want to run is a for loop simulation, say the script name is simulation.m.

I set the push button as follows.

start.button = uicontrol('Style','pushbutton','units','normalized',...
                     'String','Start','Position',[0.1,0.93,0.1,0.05], ...
                     'Callback',@start_call);

I can't figure out what to write in the callback function (either for running the script or for pausing it

function [] = start_call()
    simulation.m;
end
1

1 Answers

1
votes

You've basically got it right, you just need to add two things: the callback always takes two input arguments, so even if you don't use them, the function definition needs them. A script is run using the run command. Just change your callback to

function [] = start_call(source, eventdata)
    run('simulation.m');
end

Remark: arguments that are not used are commonly replaced by the shorthand ~, which would then read

function start_call(~, ~)

You can also obviously drop the square brackets, if there is no output.