Random Numbers in Matlab – Part I

In this series of posts, I will explain how to use the various random number generation functions in Matlab. This will include the usage of the basic commands, how to control random number generation, how to create other distributions from the basic functions that Matlab provides, and what alternatives there are to the functions used in Matlab. In this post, I will explain the basic random number generation commands in Matlab, including randrandnrandi, and randperm, and provide some example applications.

Continue reading

A Blackjack GUI in Matlab – Part IV of using Guide

With this post we wrap up our introduction to using guide with a look at the usage of a push button and a drop-down menu in our creation of a blackjack strategy guide GUI. As a look back, or to catch up, you can visit our three previous posts: Part I: Creating the layout using guide; Part II: Setting up a table; and Part III: getting user input from radio buttons and text boxes. Finally, we have also attached all of the necessary code to the end of this post to do as you please.

Continue reading

Building GUIs in Matlab – Part III Utilizing User Input

In this post we will combine the ideas presented in part I and part II on building a GUI utilizing guide in Matlab. So far we have generated two graphical windows, one of which includes radio buttons, edittable text boxes, a drop-down menu, and a push button, and the second of which has a modifiable strategy table. The object now is to combine the two windows, and allow for proper user control of all of these components.
Continue reading

Building a GUI in Matlab – Part II Tables

Last week we looked at the usage of guide in building a GUI. We included radio buttons, both editable and static text boxes, a drop-down menu and a push button. This week, we’ll create our second GUI to display a table (uitable). As all the decisions in blackjack hinge on two pieces of information: 1) the face up card of the dealer; and 2) the player cards, a look-up table can provide an optimal method for making a simple informed choice of whether to hit, stand, split or double down.
Continue reading

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.

Continue reading

Sending messages with sendmail

When running long code streams, waiting in front of the computer watching the program run can be excruciating. Sometimes I find myself doing this if I do not know how long the code will run, or if there will be errors returned. (I also sit in front of the computer because I enjoy watching cat gifs and the old school de-fragmentation screens, so who knows…) But you don’t have to! Go out and accomplish something else while your computer chugs away. With the useful command sendmail, we can send messages to our email or phone with some simple commands. Through this post, I’ll share some sample .m files that we commonly use to notify ourselves of code completion or errors.

Continue reading

Floating Point Comparisons in Matlab

A common problem in Matlab and every other programming language that uses floating point numbers is that calculations involving floats often do not yield the expected answers because of rounding, which can have undesirable effects on control statements. The immediate question is how to handle these rounding errors so that intuitively correct statements are recognized as true by a program. We would like to accomplish this while still retaining as much relevant information in the numbers as possible, thereby allowing the detection of minute differences that are not artifacts of rounding. In this post, some common errors in floating point comparisons will be discussed, as well as methods of handling these errors.

Continue reading

Conversion of Floating Point Numbers from Binary to Decimal

After introducing floating point numbers and sharing a function to convert a floating point number to its binary representation in the first two posts of this series, I would like to provide a function that converts a binary string to a floating point number. In addition. I will convert between different types of binary representations and discuss their merits.

Continue reading