MATLAB: Synchronizing simulink with m-file

simulinksynchronising simulink with matlab

im need to synchronize output from simulink with MATLAB platform
currrently what im using is (running in matlab platform)
rto = get_param(gcb,'RuntimeObject');
blockData = rto.OutputPort(1).Data ;
but it only gives me one data and it requires me to run it manaully. Need it to run in MATLAB platform automatically and in sync with the Simulink model.
Advise/Direction needed thanks.

Best Answer

You can add a listener callback that runs when the block creates outputs:
h = add_exec_event_listener(gcb, 'PostOutputs', @callbackFcn);
More information is found here under "Listening for Method Execution Events".
Related Question