About linking an m file to a GUI

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

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.
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.
adam yes I read all about it but the problem is in linking it to the old m.file . the code I already wrote is a long code with many functions and of course it is all related . so the question is how to link each part of the code with a diffrent callback function ?
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.
Jan the code is sooo long if it was a simple code and wasn't related I could link it to callbacks but the code is all related but for the GUI I have 15 pushbuttons 2 pop-up lists so it is abvious that every one should be related by a code which I can't devide to get variable seperately one seperate it I don't know even if what I say make since for the GUI
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.
adam thank you very much I didn't try it yet but I guess your answer is helpful thank you very much

Sign in to comment.

Answers (1)

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

Tags

Asked:

on 4 Jun 2017

Commented:

on 5 Jun 2017

Community Treasure Hunt

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

Start Hunting!