Stuart’s MATLAB Videos

Watch and Learn

Introduction to GUI building with GUIDE in MATLAB 8

Posted by Doug Hull,

As we approach video number three hundred on this blog, I thought it was time to remake the original video that got this all started. I still refer people to it on a weekly basis. This shows you how to make a simple GUI in MATLAB.

The basics of GUIDE are:

  • Lay out controls of the GUI
  • Wire up callbacks, the function that runs when you interact with the controls
  • Gather data from the controls

This series shows these basic skills. They allow you to make a wide array of GUIs very easily.

8 CommentsOldest to Newest

Claudio Gelmi replied on : 1 of 8

Thanks Doug for the remake of a classic! I started using Guide after watching your original video back in 2005 :)

Stefanos replied on : 4 of 8

Thanks for this. This is one of the most helpful videos ever. I keep coming back to it :D

Tzuyu replied on : 6 of 8

I am fairly new to matlab. I am making 2D Rubik’s Cube in matlab and a GUI for it. I am trying to figure out how I can make the push button work for my faces of Rubik’s cube abbreviated to ‘RLFBUD’ each time I click on GUI. I tried using handle but wasn’t able to make it work. Sorry if my question doesnt make sense at all. I am not a native speaker. Any help is highly appreciated.

Many thanks

% — Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function RC = rotation2D(RC, rot)
RC= get(handles.simple_gui, ‘RC’)
set(handles.simple_gui, ‘pushbutton7’, ‘RC’ )

Tzuyu replied on : 8 of 8

HI Stuart,

Yeah, I am still unable to make it work. Strange enough, I am not getting any error on Command Window. When I run my GUI, it asks me to input the number of rotations I want, the Cube Face rotation of my choice and whether I would like to carry on with further rotations once the former 2 rotation are carried out. But when I click on push button 7 on GUI itself, it does nothing. I believe I haven’t connected the string for rotation with my push button 7 properly and that’s the help I am looking for.

To give you a little idea of what I am talking about, here is my function and string for random rotation of my 2dRubix’s Cube.

function RC = rotation2D( RC, rot )
switch rot
case ‘r’
RC(7,6)= RCtmp(4,6);
RC(8,6)= RCtmp(5,6);
RC(9,6)= RCtmp(6,6);
RC(4,6)= RCtmp(1,6);
RC(5,6)= RCtmp(2,6);
RC(6,6)= RCtmp(3,6);
RC(1,6)= RCtmp(6,10);
RC(2,6)= RCtmp(5,10);
RC(3,6)= RCtmp(4,10);
RC(4,10)= RCtmp(9,6);
RC(5,10)= RCtmp(8,6);
RC(6,10)= RCtmp(7,6);
RC(4,7)= RCtmp(4,9);
RC(6,7)= RCtmp(4,7);
RC(6,9)= RCtmp(6,7);
RC(4,9)= RCtmp(6,9);
RC(5,7)= RCtmp(4,8);
RC(6,8)= RCtmp(5,7);
RC(5,9)= RCtmp(6,8);
RC(4,8)= RCtmp(5,9);

THESE ARE NOT MY COMPLETE CODES. They are part of it. I have 6 Cases- ‘RLUDFB’ for my clockwise direction and 6 Cases- ‘rludfb’ for my anti clockwise direction. These cases are connected to the MAIN FUNCTION below and I have copy pasted the same MAIN FUNCTION IN THE OPENING FUNCTION OF GUI AND IT WORKS; however, push buttons doesn’t work at all. –

function main

rc = makerandom(rc)
rc = choosemove(rc)

As you can see in my previous post, these are what I have under my pushbutton 7 to make it work for my Case ‘F’

function RC = rotation2D(RC, rot)
RC= get(handles.simple_gui, ‘RC’)
set(handles.simple_gui, ‘pushbutton7’, ‘RC’ )

Sorry for the wall of text and if it’s not clear enough. I tried my best to explain what my problems are and what I expect to get from my GUI. Any help is highly appreciated.

Many thanks

Add A Comment

What is 4 + 6?

Preview: hide