Week+of+2-11+to+2-17

Chapter 10 is concerned with making a GUI tool useful - taking a model or function we already use or know in MATLAB, and making it interactive and visual via a GUI. I revisited my "MATLAB Goals" page and realized that now would be the perfect time to begin tackling some of the early ones. After skimming the chapter, I decided it would probably benefit me to work my way through the concepts of this chapter by designing the straight line GUI described in the "Goals" page. The book divides the process into a series of steps, the first being Step 0: Write and Debug the Program. So, I set out to graph a simple program to graph y=mx+b with user inputs of m and b as well as min x and max x. The resulting program is shown below. Just to make sure things were all set, I did a very simple test of this function, shown below. Step 1 in Chapter 10's process is to plan the GUI. For me, I imagine the m and b inputs should be text boxes for freedom of choice by the user, and the x min and x max should be slider bars so the users can dynamically change the window they are concerned with. Step 2 is to actualize this vision using GUIDE and creating the basic skeleton of the GUI. The other part of Step 2 is to clean up the tags and values as much as possible before integrating the script. I did so, and below is a snapshot of the result. Step 3 is to turn the script into a function which calls upon GUI handles and such. The book suggests to name it the same thing as the original script but with an "F" at the end do denote that this is the function. Below is a picture of my new code, replacing the values the GUI will manipulate with handles so that the function will need the GUI input. Step 4 is about having the script that governs the GUI actually use the function you crafted. In order to have this function be executed at all the necessary times, it appears that, based on the way the book lays things out, I will need to insert this function into the Opening Function and the Callback Functions involved in the Tool Script. I merely need to add the line "StraightLineF(handles);" into each of these functions and that should coordinate my function with the GUI. I got a little snagged up at this point and began to get cryptic errors when I tried to run the Tool, but once I tweaked a few things and investigated a little bit, I realized I had forgotten to edit the Tag of the Axes object when I was doing my re-tagging. I was referring to "plotAxes" when I had never actually tagged anything as "plotAxes". Once I went back into GUIDE and fixed that in the inspector, I had myself a functioning GUI. Below is a picture of the GUI in action. Clearly, this GUI is a little messed up. The way I have things set up, the line is always a perfect diagonal, the only thing that changes is the scale displayed on the axes. In addition, the x minimum and x maximum slider bars are very easily set in conflict with each other (for example where the maximum is lower than the minimum) and the GUI pops out an error message every time this happens. So, I will likely spend some time in a future post or two attempting to clean things up. Either way, it is kind of cool to have built a GUI that uses a function I wrote.