G-dac project

 Introduction :
    This is typical MATLAB based graph plotting application. No big code. noting .. Just a simple GUI application developed on MATLAB. This is my first important output project after learning MATLAB coding in my 1st year summer vacations.

Platform :
  To develop this GUI based application. I have used :
  1) Windows 8.1 64 bit system
  2) MATLAB-R2008a version 7.6
  3) GUI toolbox from mathworks.

  Application :
       1)This application , when modified further , can be used in many educational ares. Such as to learn plotting basics in high school level. Also in engineering to study the nature of the plot and all these things.
       2)This application will be basic building block of my plot following robot. The concept of plot following robot (which I am going to introduce ) is -  When you will plot some function over g-dac and want to explorer it's nature on seeing in object moving in the real world like any small bot. Then in this gdac plot following robot project. You will enter some defined plot say - sin(x). You will give some values for range. Using user input and you will see your bot following same curve on floor. So this may give you real idea of the plot. So this can be it's application in robotic field. 

Current Status :
      As per current status of this application we can plot only defined function. G - dac includes sin(x), cos(x) , and tan(x) functions to plot. It receives input from user for the initial and final values for x i.e the range of the plot to be plotted . Then these input value are processed inside the matlab code , and standered GUI results on the axis are plotted.



                              As shown in the figure. x start: is the text input where user has to enter start value for x and similarly x stop : is the input were user has to enter last value of x. Three radio buttons provided downside are ment to plot the graph. labes for x axis y axis and title are included in the code.         

Code :
        The code for this application is GUI based code in MATLAB. The .M file for this figure is shown here :
   

   

Here. MATLAB's guide toolbar can provide us the way to design our GUI. It's easy by just using command --> guide in command window in matlab.
              First, we created a axis on right side by selecting axes tab from uicontrol toolbox. Then added three radio buttons. To set their properties , we have to just double click on respective radio button and property inspector will be opened. And select 'Sting' property as the name of perticular function you have to plot. And let 'tag' remain as it is. Then it's all about coding after you put text strings and static text strings as per our reqirements.
        In coding , we have this gui's .M file. M file is the basic script file in matlab. And we are going to write codes for our matlab GUI here.''
       First in radiobutton4 callback function. we will write --
   i = get(handles.input1,'String');       j = get(handles.input2,'String');
here handles.input will provide us the handle to our object 'text edit' which has tag 'input1'.And then get function will store value of 'String' property into variable i. Here value of String property will be the value of string which is entered in the text field by the user i.e the value of x start : and x stop : respectively in two textboxes. Now we have value of i, and j corresponding to x start : and x stop :
Now in this callback function wee have to plot sine() function. So here we will write :
     x = i:0.01:j;
    y = sin(x);
    plot(x,y);
    xlabel('x axis');
    ylabel('y axis');
    title('desired graph');
first instruction sets values of x from i to j with the steps of 0.01. Here we are creating vector x containing (j-i)/0.01 values ! . And we will send this vector to sin(x) to create y vector containing values corresponding to x to be plotted on the plot. Now using plot function in matlab. We can create our required plot on axes. Here there is no requirement to give handle of axes object. If we woud not used this axes as a object on our GUI then malatb would open new figure window whenever plot(x,y) function is executed. But still it won't because we are using axes as an object in our GUI.
          Now for the next part, we just have to copy the same code for all remaining radio buttons as it is with some modification. First modification will be object's tag name with handle. And another will be functions to be plotted with it. So for each radio button we will use any function we want. But this function should be defined in the matlab otherwise we can create our own function also.  
                        In text input , we are getting input from user in string format, or we can say we are getting a string array as an input. This string can't be processed with x = i:0.01:j statement . This statement is asking for integers(or flot values to be more specific) only,it can't work on strings. So it is necessary to conver string number into actual double data type in matlab. And same is done with this str2num(); function in matlab. So wathever data user enter in text box , it is getting converted into real numbers to work with.If user enter any letters like 'A' ,'g' . It won't work. In that case it will simply convert it to it's ascii value.
For more information about ascii values visit here : 
        more about ascii -- >http://www.ascii.cl/ 
                   Next step of this project can be to have a general mechanism , using text box so that user can easily type the function like sin(x) , atan(x) , log(x). etc. Without having any need to use different toggle buttons or radio buttons. So this is the first modification of this application - having a general purpose text input box to allow user to input required function. Here code will be little bit larger. We will actually compare strings entered by the user. And will decide which function we have to do when particular string is entered by the user. And here we go. Just creat one text box having tag as per our convenience so that we can refer it easily.
                  Image shown below indicates our new 'edit text' object .
MATLAB aromatically creates callback function for it. Now we just need to write proper code in it to compare the input string and do designated task after comparison.

                   Code for each callback is like this:
  function edit3_Callback(hObject, eventdata, handles)
    in = get(handles.edit3,'String');
   if in == 'sin(x)'
        i = get(handles.input1,'String');
        j = get(handles.input2,'String');
        i = str2num(i); % in real value
        j = str2num(j); % in real value
        x = i:0.01:j ;
        y = sin(x);
        plot(x,y);
        xlabel('x axis --->');
        ylabel('y axis --->');
        title('Desired graph');
    end
   
    if in == 'exp(x)'
        i = get(handles.input1,'String');
        j = get(handles.input2,'String');
        i = str2num(i); % in real value
        j = str2num(j); % in real value
        x = i:0.01:j ;
        y = exp(x);
        plot(x,y);
        xlabel('x axis --->');
        ylabel('y axis --->');
        title('Desired graph');
    end

          Here we are juct comparing input string with name of funtion. We are storing input string in variable 'in' and then we are comparing for each function using if statement. Note that 'end' is necessary after if statements. And after that comparing string we are just writing code for that perticular function plotting.
             One thing should be noted here that while comparinf strings we have assumed that useer have entered the x star : and x stop : values in tags - 'input1' & 'input2'. So if we want to make our program more general and user friendly, we can add additional condition to check weather 'input1' and 'input2' have got any input or not and then accordingly allow edit3 tag to perform it's function.