Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I run an m-file through GUI?

975 views
Skip to first unread message

George Mitregas

unread,
Sep 30, 2008, 12:30:05 AM9/30/08
to
I have created a GUI and a different m-file which has the variable "xfinal" as output (It is a 5x1 matrix actually). I want to produce the elements of xfinal in edit texts in my GUI when I press a pushbutton. I made xfinal a global variable in order to succeed my goal but I realized that when I change some parameters in the m-file, the GUI results are the same, unless I run the m-file.
Is there any command for GUI that when I push the pushbutton it will force the m-file to run?

Matt Fig

unread,
Sep 30, 2008, 1:21:01 AM9/30/08
to
You can put the M-File in the callback of the pushbutton. I recommend against using globals to do this though. Here is an alternative way to do what you want. Put both functions below into the same M-File, as shown, and run it to see how it works.


function [] = examplegui2()

figure('pos',[300 200 200 180],'men','n');
edit1 = uicontrol('sty','ed','str','Blank',...
'pos',[10 60 180 20]);
edit2 = uicontrol('sty','ed','str','Blank',...
'pos',[10 100 180 20]);
edit3 = uicontrol('sty','ed','str','Blank',...
'pos',[10 140 180 20]);
push = uicontrol('sty','pu','str','Push to fill edits',...
'call',{@pushcb,edit1,edit2,edit3},'pos',[10 20 180 20]);


function [] = pushcb(hand,evnt,edit1,edit2,edit3)
% Callback for popupmenu.
set(edit1,'str',floor(rand*1000));
set(edit2,'str',floor(rand*1000));
set(edit3,'str',floor(rand*1000));

George Mitregas

unread,
Sep 30, 2008, 2:11:01 AM9/30/08
to
"Matt Fig" <spam...@yahoo.com> wrote in message <gbscvt$nrd$1...@fred.mathworks.com>...


Thank you very much!

d.aishw...@gmail.com

unread,
Apr 21, 2014, 8:08:32 AM4/21/14
to
I want to create a GUI to run the algorithms which is in .m file. what should be the syntax for invoking/run .m file (Push button) in the calling function?

Jeff

unread,
Apr 21, 2014, 3:31:08 PM4/21/14
to
If you are building the GUI using GUIDE follow these steps.

1. Right click on the button, hover over "View Callbacks", then select Callback. This will take you to the code editor and more precisely the function that is called when the button is clicked. If your button's name is RunCode the callback function will be called RunCode_Callback((hObject, eventdata, handles).

2. In this code block type the file name for the code you want to run. If the name of the .m file is myCode.m then simply type myCode. The function will look something like the following.

% --- Executes on button press in RunCode.
function RunCode_Callback((hObject, eventdata, handles)
% hObject handle to RunCode (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
myCode

The lines beginning with a % are commented lines. They can be deleted if you want. However, I would suggest leaving them in until you are more familiar with MatLab as they do provide some useful information.
0 new messages