Search code examples
matlab-gui

GUI for my matlab project using GUIDE


I have developed a matlab project which includes main.m file which calls different functions.Now I want to develop a GUI around the code using GUIDE.How can I input image from GUI and display results calculated by my project in the GUI.


Solution

    1. First, of course, you need the main screen.
    2. Then add a pushbutton on it using "uicontrol" function.
    3. Next you need to set the event handler. An event, in your case, happens when the user clicks the pushbutton, or points cursor on it, etc.
    4. In the event handler, you must ask the user to choose an image.
    5. Open image with received location.
    6. Execute your code and save results in the handler. Handler is a structure with handles and user data.
    7. Show results on screen.

    Generic code below could help you with the pushbutton event handler:

    function pushbuttonCallback(hObject, eventdata, handles)
    [fileName Dir] = uigetfile('*.jpg','select jpg file');
    imageDir = strcat(Dir, fileName);
    I = imread(imageDir);
    ** YOUR FUNCTION HERE **
    handles.results = YOUR FUNCTION'S RESULTS;
    guidata(hObject, handles);
    

    Comments

    I'm assuming at this point you already have a pushbutton on your GUI.

    Note that code above only save your results in the handler structure. You need to use it to show data on screen depending on the type of result you get from your function.