About linking an m file to a GUI
Show older comments
I am working on a project to analyse some signals after finishing the code my supervisor asked me to do GUI and I have no idea about that one. I made the interface but the problem I can't understand the callback codes so I can change the code properly to get along with the m.file. In the interface I have a pop-up list in which i should call a list of signals from a database. I have some pushbotton that should make some changes on the figure and some others to show a list of results. values that should be entred by the user to be changed in the m.file code. I guess these are many questions to ask but I really need help
7 Comments
Jan
on 5 Jun 2017
To be exact: There is no question. It would be easier to answer if you ask a specific question. Post the current code and explain, what you want to change or achieve.
Adam
on 5 Jun 2017
Have you read the documentation and its GUI examples? It's usually a good place to start. Questions like 'what is a callback?' are clearly answered there and with examples.
wissal dakhli
on 5 Jun 2017
Adam
on 5 Jun 2017
Each function can live in its own file and these can be called from anywhere you want, including callbacks. Don't put all your code in one file. You can't just link a GUI to a pre-existing m-file that contains a load of sub-functions, you have to redesign it to work with a GUI, but if it is already in functions then that is easy, if it isn't then the first job is to break it down into functions.
function someButtonCallback( hObject, src, evt )
runMyFunction(...)
is a simple pushbutton callback that will just call code from a completely different function.
wissal dakhli
on 5 Jun 2017
Adam
on 5 Jun 2017
15 pushbuttons implies 15 entry points which implies 15 functions (at least). The fact that they are all related doesn't mean they can't still be broken up. The GUI and, for example, the handles structure, is the glue that holds it together by storing the data in a way that it is accessible in all callbacks.
wissal dakhli
on 5 Jun 2017
Answers (1)
ES
on 5 Jun 2017
callbacks are simple function that execute on an event (for example a push button press). assume that you have value in an edit box1 (editbox1). assume that you have a value in another edit box(editbox2). assume that you have a push button(pushbutton1) upon pressing which the sum of values is edit box1 and edit box2 are computed and displayed in edit box 3.
The code has to be implemented as a callback of the push button. the code will look like,
function pushbutton1_callback(handles, hObject....)
EB1Value = str2num(get(handles.editbox1, 'string'));
EB2Value = str2num(get(handles.editbox2, 'string'));
sum_EB = EB1Value+Eb2Value;
set(handles.editbox3, 'String',num2str(sum_EB));
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!