MATLAB Answers


How do I run a program (.m) from simulink (.mdl) using a button?

Asked by Ayache Khadidja on 5 Dec 2012

Hi every body

I would run a program (.m) from my model simulink (.mdl) using a button.

Do you have any idea?

Thank you


2 Answers

Answer by Kye Taylor
on 5 Dec 2012
Edited by Kye Taylor
on 5 Dec 2012
 Accepted answer

One approach (short version):

Add an annotation to your model, and write the command invoking your program in the annotation's properties' ClickFcn.

For more details, type

doc simulink.annotation

and look at the ClickFcn property.

(long version) Open your model, and double click anywhere on the background. This will add a annoation and a blinking cursor. Type in your annotation and hit escape to stop entering text. Right-click on the annotation and select Properties from the context menu. There is a text area (ClickFcn) to specify the commands to be executed when the annotation is clicked by a user.


Answer by Ayache Khadidja on 5 Dec 2012

Thank you so much.

It works very well :)


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!