Building a GUI in Matlab using Guide – Part I

Users crave the ability to use graphical user interfaces (GUIs) to perform tasks. While command line input can be beneficial and easier to implement (see our previous post on user inputs), error handling and decision making can be more intuitive through a GUI. Over the next several weeks, we’ll demonstrate the wonderful capabilities of Matlab in creating such GUIs. Using the Matlab built-in GUI building tool guide, we will build a functional program that takes in user inputs and displays useful information. In order to make this exercise fun, we’ll be creating a GUI that provides the optimum strategy for decision making in the game of blackjack.

To begin, let’s layout the components of our interface. If you are unfamiliar with the game, a brief explanation is included at the end of this post (go to the *). Start by running the command “guide” in Matlab. When you do so, the following pop-up window will appear:
Matlab's guide start window

Select the default blank GUI option and click OK. You will now have the following workspace where you can drag and drop elements into your interface.
Matlab Guide blank GUI

Simply drag and drop items from the left 2 columns into the grid area to create your GUI! Simple right? The different types of components are as follows:
Matlab GUI components

When you insert a component into the grid, you can edit its properties by selecting the component, right-clicking, and selecting “Property Inspector”. For our dealer Ace card radio button, here is a look at our current settings:
Matlab GUI property inspector

Our final product (admittedly more utilitarian than aesthetic…) looks as follows:
Matlab user interface for blackjack strategy

In order to provide the greatest coverage of the GUI tools, we’ll utilize radio buttons for the dealer’s card (enclosed within a radio button group), text boxes for the player’s two cards, an un-editable basic strategy text box to output the decision, static text to label the sections, a drop down menu to pop-up some basic strategy tables, and a push button to perform the decision. Feel free to play around with the other GUI tools as well, though we will not discuss them in this series of posts.

When satisfied with your interface, save the figure. Matlab will automatically generate an associated m-file of the same name, with basic functions for the components. In the following posts, we will begin using this template for further coding, to develop program functionality.  In the next post we will investigate the creation of tables (uitable) to display optimal player decisions, and in Part III look at acquiring user input from the radio buttons and text boxes.

 

* Basic Blackjack Rules

In the game of blackjack, the player is dealt two cards face-up, from a standard 52-card deck of cards (multiple decks might be used as well). The dealer, or house, is also dealt 2 cards, with one card face down and the other face up. The object of the game, for the player, is to defeat the dealer (It’s not necessarily to get as close to 21! It doesn’t matter what you end up with, only that your hand can hold up against the dealer). The player can win by: 1) getting a blackjack (Ace + A ten, where ten equals T, J, Q, K); 2) Having a hand who’s cards add up to a value greater than the dealers, without exceeding 21; or 3) The dealer busting (exceeding 21). The house has certain rules, mainly always hitting on hand values of soft 17 or less. As an ace can equal 1 or 11, soft 17 means an Ace and a 6.

Regardless, the player has a few options to consider when playing.
1) Hit: The player is asking for additional cards. For example if you have a 5 and a 2, for a total of 7, you’d always want to hit, as any card will improve your handing, without a risk for busting;

2) Stand: Keep your hand as is. There are certain hands where this is obvious, i.e. a T and a 9, for a total of 19. No matter what card the dealer is showing in this scenario, hitting would be bad, as only an Ace or a 2 would improve your hand, all other cards (3-T) would make you bust (~85%);

3) Split: When a player is dealt a pair, you can double the bet and split up the hand into two hands. For example, if dealt A-A, you can now resume playing with 2 hands, where each one starts with a lone A;

4) Double Down: In this case your are hedging that your hand will defeat the dealer, so you double the bet, and receive only a single card. This is an optimum strategy when a dealer is showing for example a 6, and you have a hand that sums up to 11. You are first off hoping to get a single high card, preferably a 10, to make a strong hand, but in the off chance you don’t, you still will win a large amount of time when the dealer busts.

6 thoughts on “Building a GUI in Matlab using Guide – Part I

  1. Complete couse on Matlab GUI on udemy with very cheap prices Matlab Graphical User Interface using Guide (Codes Include) The course is 50 percent off for the first 10 people (deadline to avail the 50 percent off is 20th of october 2016)

    • Complete couse on Matlab GUI on udemy with very cheap prices Matlab Graphical User Interface using Guide (Codes Include) The course is 50 percent off for the first 10 people (deadline to avail the 50 percent off is 20th of october 2016)

Leave a Reply to purna chander Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.