MATLAB GUI Tutorial Easy Step by Step Explanation (Calculator Example)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi in this tutorial I will show you how to make a simple calculator using MATLAB GUI guide by doing this it will get a good basics for di making in general let's start make sure that you are in the right directory make new folder name it as you wish and set it as your current folder go to the new option at home panel and choose graphical user interface check blank GUI and click ok you get a blank canvas for editing you can change its size by dragging the lower right corner on the left side there is a panel with objects such as buttons pop-up menus checkboxes etc and first object that will use is edit box choose it and stretch it with the left mouse button on the canvas then choose button object and do the same we'll need a bunch of buttons by holding left shift and using a left mouse click you can select multiple objects after which you can copy and paste the selection to speed up the process of drawing you static text object is used to add descriptions on the GUI canvas when you right mouse click on the static text box you made go to the property inspector and you'll get a window with many setup options you can change the font size then change the text content under a field string you can do the same for edit box because all the calculators are right side oriented you can set up the Edit box to be as such delete the content of string field to make it blank field tag is the most important field because it names the function in the code assigned to the object I'll type screen and that will be the callback for this object for buttons I'll do the same except for the field string where I'll put the numbers operation signs etc you you can select multiple objects and change a common setup in the property inspector for all of them like font size in this case now when the drawing job is done by clicking on the green play button I will run the code but before that you must save your program it will save to files dot F ID which is file for DUI and dot M which is file where the callback code is sword after this the program is executed you can click on the buttons but nothing happens I must type the code to make it alive the window in editor is opened automatically we need callbacks because callbacks are the functions attached to the program objects other functions are auto-generated and in this tutorial we won't be bothering with them first I'll set up the numbers variable as loads content of the screen the variable is used only under this function handles dot screen associate with the screen scroll back and get function loads the string stored in the screen set function does the opposite it writes to the screen as the architect function concatenates string that is previously loaded from the screen with one more number let's test it you now I do the same for all numbers use copy paste you next I'll set up the see reset button it just writes an empty string on the screen you to make an operator function I'll need to use global variables that means that define declare some variable as global under a function it could be loaded into some other function in program by also declaring the same variable under it and vice-versa it is the most important trick in GUI making I'll need two global variables a for loading the type number for the operation and the selector will be explained later I must also convert the string to number before assigning it to global variable a after loading the number from the screen we need to reset the screen for typing the second number for the operation so I use expression as in the reset function I'll do the same for other operations give other names to the variables like BCD and associate other numbers to the selector variable 2 3 4 when you enter the second number you'll click equals to get the result under function equals first I'll declare all global variables that we need now is the time to use the selector variable for the case function selector defines which operation will be executed notice that I do not need for global variables ABCD I could use only one for all the operations but never mind you'll be smarter string to number is used when you're loading second operand that is written on the screen and you type it back first converting it from number to string set up all four cases and that's it let's test it you now I'll change the minus function I want it to recognize the blank screen and when you click on a - button - type - all I need is one if-else statement when you run the code first click the C once it load screen with an empty string then the statement works perfectly next is programming the constant PI loading it needs to be loaded when the screen is empty and not when something is already typed one if statement is enough STR cmp e function compares two strings and returns zero if they are different and one if they are the same so pi is typed only when the screen is empty also click see once before trying you Square and root buttons I'll program to work on click no need to use them under equals function you one more thing is to set up the comma not to be timed to when the screen is empty you that's about it my goal wasn't to make a perfect calculator but to explain some basic GUI functionalities I hope it helped you with your assignments if you have some questions or requests feel free to write me I'll consider them and maybe do more videos to support me you can subscribe to this and my other channels morning vibes it's an artistic project I work on it regards ambiental sound recordings check it out in this video's description bye
Info
Channel: digital_vibes
Views: 13,071
Rating: 4.9195981 out of 5
Keywords: matlab gui tutorial, tutorial, matlab, gui, gui tutorial, calculator gui, calculator, calculator tutorial, matlab gui, beginner, matlab beginner, learn matlab, matlab course, matlab programming, matlab basics, start matlab, digital vibes
Id: LEmV1pnymn4
Channel Id: undefined
Length: 12min 13sec (733 seconds)
Published: Wed Dec 18 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.