synchronizing simulink with m-file

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.

 채택된 답변

Jarrod Rivituso
Jarrod Rivituso 2011년 4월 14일

1 개 추천

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".

댓글 수: 1

Jarrod Rivituso
Jarrod Rivituso 2011년 4월 14일
I should mention also that there are blocks you can include in your model that will allow you to run MATLAB code from within Simulink, such as the "MATLAB Function" block, or the MATLAB S-function block.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Tan Edwin
Tan Edwin 2011년 4월 18일

0 개 추천

How do i actually add this code in?
let say my i want to call is:
function rto=access()
rto = get_param(gcb,'RuntimeObject');
blockData = rto.OutputPort(1).Data ;
rto %to get output into MATLAB workspace every iteration in simulink
So can i place the event listener into a lvl-1 S-function block or does it only works for lvl2 S-function block? where should i place it? in the update/output?

댓글 수: 6

Tan Edwin
Tan Edwin 2011년 4월 18일
i place the listener in the output function in a lvl 1 S-function and it did not work. Do i need to modify my m-file as well?
Jarrod Rivituso
Jarrod Rivituso 2011년 4월 18일
When taking the callback approach, you should write a MATLAB function to serve as the callback. You write this outside of an S-function. The callback must have certain inputs, as shown in the doc example:
function callbackFcn(block, eventData)
blockData = block.OutputPort(1).Data ;
So, you don't need to get the runtime object again, and the callback function will be called at each simulation step.
Tan Edwin
Tan Edwin 2011년 4월 19일
Will the callbackFcn output values in the MATLAB workspace as a form of .mat file?
cos i need the .mat file at each instance of the simulation step, but i cant seems to see the output from the callbackFcn even if i remove ';' from the blockData line?
Jarrod Rivituso
Jarrod Rivituso 2011년 4월 19일
Do you really want a .mat file for each time step? That seems excessive - there could easily be thousands of time steps in a single simulation.
The rules for the callback function are the same with any function. Each function is given its own workspace, which is separate from the base workspace.
What exactly are you trying to accomplish here? I have a hunch there may be other ways you could do this besides outputting a .mat file for each time step.
For instance, you can use signal logging to log simulation data throughout an entire simulation very easily:
http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/ug/brh7636.html
Tan Edwin
Tan Edwin 2011년 4월 20일
Thanks alot for the advices. Will look into signal logging method.
By the way the link is not working.
Jarrod Rivituso
Jarrod Rivituso 2011년 4월 20일
Ooops, looks like it changed. Here ya go
http://www.mathworks.com/help/toolbox/simulink/ug/f11-47048.html

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Event Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by