Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Select your favorite topic

MATLAB GUI & EXCEL

function gui_excel()
%MATLAB example to demonstrate the GUI and export the values to spreadsheethttp://www.assoc-amazon.com/e/ir?t=m089e-20&l=btl&camp=213689&creative=392969&o=1&a=1584883200.
%The sample registration form will get the data and store it in a excel sheet.
%NOTE: Do not open sample.xls while executing because data inconsistency may occur.
%While executing, a warning message will appear to notify the user that 
%addition of new spreadsheet by name SAMPLE FORM is created.




%Delete the file if exists already.

if('sample.xls')
    delete sample.xls;
end
%To clear all the values present in the global varibles.
clear all;
global file_handler  file_string  Nxt  dd  mm  year  age_today;
file_handler=2;
%Export the column names to the excel sheet.

A={'NAME','DATE OF BIRTH','AGE','ADDRESS','EMAIL ID','PHONE NUMBER'};
%Here sample.xls is created and it will be in the MATLAB current directory
xlswrite('sample.xls',A,'SAMPLE FORM','A1');%filename, matrix,sheetname and the range is specified
figure('units','pixels','position',[250 100 500 450],'menubar','none','numbertitle','off',...
            'name','GUI & EXCEL(2)','resize','off');
        title('SAMPLE REGISTRATION FORM','fontsize',20,'fontname','Time New Roman','color','r');
        axis off;
        Rform();%call the function Rform to fill the form
    function Rform(source,eventdata)
 uicontrol('style','push','units','pixels','position',[15 380 150 30],...
                 'fontsize',10,'string','ENTER YOUR NAME');
 uicontrol('style','push','units','pixels','position',[15 300 150 30],...
                 'fontsize',10,'string','DATE OF BIRTH');
  uicontrol('style','push','units','pixels','position',[15 250 150 30],...
                 'fontsize',10,'string','AGE');
  uicontrol('style','push','units','pixels','position',[15 200 150 30],...
                 'fontsize',10,'string','ADDRESS');
  uicontrol('style','push','units','pixels','position',[15 100 150 30],...
                 'fontsize',10,'string','EMAIL ID');
  uicontrol('style','push','units','pixels','position',[15 50 150 30],...
                 'fontsize',10,'string','PHONE NUMBER');
 
     
        file_string=num2str(file_handler);
     
   uicontrol('style','edit','units','pixels','position',[200 380 250 30],...
                 'fontsize',14,'callback',{@nam_call});
             uicontrol('style','text','position',[200 340 50 20],'fontsize',14,'string','DD');
 uicontrol('style','edit','units','pixels','position',[200 300 50 30],...
                 'fontsize',14,'callback',{@dob_call1});
             uicontrol('style','text','position',[280 340 50 20],'fontsize',14,'string','MM');
        uicontrol('style','edit','units','pixels','position',[280 300 50 30],...
                 'fontsize',14,'callback',{@dob_call2});
             uicontrol('style','text','position',[360 340 50 20],'fontsize',14,'string','YYYY');
             uicontrol('style','edit','units','pixels','position',[360 300 90 30],...
                 'fontsize',14,'callback',{@dob_call3});
 uicontrol('style','text','units','pixels','position',[200 250 250 30],...
                 'fontsize',14);
 uicontrol('style','edit','units','pixels','position',[200 150 250 80],...
                 'fontsize',14,'callback',{@add_call});
  uicontrol('style','edit','units','pixels','position',[200 100 250 30],...
                 'fontsize',14,'callback',{@email_call});
  uicontrol('style','edit','units','pixels','position',[200 50 250 30],...
                 'fontsize',14,'callback',{@phone_call});
   okButton=uicontrol('style','push','position',[200,10,30,30],'string','OK','callback',{@finish});
   Nxt=uicontrol('style','push','position',[400,10,50,30],'string','NEXT','callback',{@next_call});
   set(Nxt,'Visible','off');

   %writing to the excel sheet
    function phone_call(source,eventdata)
       pno=get(source,'String');
       pnum={pno};
       xlswrite('sample.xls',pnum,'SAMPLE FORM' ,strcat('F',file_string));
    end

function email_call(source,eventdata)
       mail=get(source,'String');
       e={mail};
       xlswrite('sample.xls',e,'SAMPLE FORM' ,strcat('E',file_string));
end
    function add_call(source,eventdata)
       address=get(source,'String');
       add1={address};
       xlswrite('sample.xls',add1,'SAMPLE FORM' ,strcat('D',file_string));
    end
    function  age_call(source,eventdata)
       age=get(source,'String');
    
    end
 
 
    function dob_call1(source,eventdata)
       dd=get(source,'String');
    end
    function dob_call2(source,eventdata)
       mm=get(source,'String');
    end

        function dob_call3(source,eventdata)
       year=get(source,'String');
       
           dob=strcat(dd,'-', mm,'-', year);
           b={dob};
     xlswrite('sample.xls',b,'SAMPLE FORM' ,strcat('B',file_string));
     age_calculator();
    end
     
 
 













 
    function nam_call(source,eventdata)
       names=get(source,'String');
       nam1={names};
     xlswrite('sample.xls',nam1,'SAMPLE FORM',strcat('A',file_string));
        end
 
 
    function finish(source,eventdata)
        set(Nxt,'Visible','on');
        set(okButton,'Visible','off');
    end
    end

%Pushbutton NEXT calls the Rform to fill another form
    function next_call(source,eventdata)
        set(Nxt,'Visible','off');
        file_handler=file_handler+1;%handle is incremented to point the next position in the excel sheet
        Rform();
    end

%calcute the age automatically
    function age_calculator()
        now=date;
        dv=datevec(now);% date vector returns in yyyy mm dd format
     
        dd1=str2num(dd);
        dd_diff=dv(3)-dd1;
     
       mm1=str2num(mm);
       mm_diff=dv(2)-mm1;
    
       years=str2num(year);
       year_diff=dv(1)-years;
    
       if(mm_diff <= 0)
           if(dd_diff <= 0)
               age_today=year_diff-1;
           end
       else
           age_today=year_diff;
       end
       uicontrol('style','text','units','pixels','position',[200 250 250 30],...
                 'fontsize',10,'string',age_today);
             age1={age_today};
       xlswrite('sample.xls',age1,'SAMPLE FORM' ,strcat('C',file_string));
    end
      end





Running the GUI: Fill the form and press ok. Click Next button to fill another form. The data will be stored in the excel sheet.
like button Like "IMAGE PROCESSING" page

4 comments:

julie anderson said... Reply to comment

How to make the sample form;The code of it is mentioned clearly.By using some code we can make the forms.

Free sample forms

Nuraeni Ratnawati said... Reply to comment

please, give me code for denoising with Median filter method using GUI at Matlab.. please, for my final test

Rajesh K said... Reply to comment

? Undefined function or variable 'dd'.

Error in ==> age_calculator at 5
dd1=str2num(dd);
I found these errors when i run your pgm....
??? Undefined function or variable 'file_handler'.

Error in ==> Rform at 16
file_string=num2str(file_handler);

Aaron Angel said... Reply to comment

@Rajesh K

Try to copy the code from the very first line
function gui_excel()

The above code is a function, so save it with the same name as the function name gui_excel.m and then run the code.

Enjoyed Reading? Share Your Views

Previous Post Next Post Home
Related Posts Plugin for WordPress, Blogger...
Google ping Hypersmash.com