MATLAB Answers


run m-file from push button in Matlab GUI

Asked by jueves jevesion on 10 Apr 2012


I need to run an untitled.m (mfile) by hitting an push button in GUI. This m-file is a script. It contains only some variables. These variables are just numbers, not an array or structure..etc.These numbers are needed for running simulink model.

So this is my problem. GUI,2 buttons, one runs mfile,second runs simulink model using data from mfile. I tried several things which i found using google,i solved nothing

Any ideas? Thanks a lot for your time and help

  1 Comment

Rick Rosson
on 10 Apr 2012

Is the untitled.m file saved to disk, or is it only in memory?


No products are associated with this question.

2 Answers

Answer by Sean de Wolski
on 10 Apr 2012
 Accepted answer



In the callback function of the pusbutton.

More per Feedback

If no error is being thrown then it is most likely running. The issue you are seeing is that it's running, generating all of those constants in the callback function workspace and then they are cleared when the callback ends. If you would liek them in the base, then use ASSIGNIN or EVALIN to move those variables from the Callback workspace to the base workspace.

doc evalin
doc assignin

  1 Comment

jueves jevesion on 10 Apr 2012

to be perfectly clearly, i tried this. when i ran the gui and push the button there were no errors, but it seemed like nothing happened. nothing in workspace

Answer by jueves jevesion on 10 Apr 2012

This is the button code: "function pushbutton2_Callback(hObject, eventdata, handles)"

@Sean de Wolski If you mean this "function pushbutton2_Callback(hObject, eventdata, handles) untitled"

This was the first thing i tried before i started searching for solutions. I also tried putting these in callback'untitled'),untitled.m on

@Rick Rosson the untitled.m file is on disk, in the same folder as the gui.

  1 Comment

Sean de Wolski
on 10 Apr 2012

See the edits to my answer.

Discover MakerZone

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

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!