MATLAB Examples

Using the Google Toolbox

By Matthew Simoneau

This is a basic introduction to the Google Toolbox, available on the MATLAB Central File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=1613

Contents

Setup

Download this submission and put the M-files on your MATLAB path. One way to do this is to add the directory containing them with ADDPATH. For more information on ADDPATH, see http://www.mathworks.com/access/helpdesk/help/techdoc/ref/addpath.shtml.

cd P:\Matthew_Simoneau\google
addpath(pwd)

Go to http://www.google.com/apis/ and download the developer's kit. Unzip the download and copy googleapi.jar to a convenient place.

zipUrl = 'http://api.google.com/googleapi.zip';
unzip(zipUrl,'.')

Add JAR file to your Java classpath. On older versions of MATLAB, you need to modify toolbox/local/classpath.txt, but on newer versions you can use JAVAADDPATH. For more info, see http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f4867.html.

%edit classpath.txt
javaaddpath(fullfile(pwd,'googleapi','googleapi.jar'))

Back at Google's site, http://www.google.com/apis/, create a Google account. You'll just need to give them your e-mail address so they can validate it and send you an access key.

web http://www.google.com/apis/ -browser

Before using the functions, set the key in your preferences:

%key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
setpref('google','key',key);

Finding Pages about MATLAB

Now use GOOGLESEARCH to get information about a search for "matlab".

s = googlesearch('matlab',30);
disp(s)
                ResultElements: [1x30 struct]
                   SearchQuery: 'matlab'
                    StartIndex: 1
                      EndIndex: 30
             DocumentFiltering: 0
    EstimatedTotalResultsCount: 28700000
               EstimateIsExact: 0
                SearchComments: ''
                    SearchTime: 0.2681
                    SearchTips: ''
           DirectoryCategories: []

disp(char(s.ResultElements.URL))
http://www.mathworks.com/                                          
http://www.mathworks.com/products/matlab/                          
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.shtml 
http://www.mathworks.com/access/helpdesk/help/helpdesk.html        
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.html  
http://www.mathworks.com/academia/                                 
http://www.math.utah.edu/lab/ms/matlab/matlab.html                 
http://www.math.ufl.edu/help/matlab-tutorial/                      
http://math.ucsd.edu/~driver/21d-s99/matlab-primer.html            
http://www.math.mtu.edu/~msgocken/intro/intro.html                 
http://www.mathtools.net/MATLAB/index.html                         
http://www.mathtools.net/                                          
http://www.mathworks.co.uk/products/matlab                         
http://www.mathworks.com/academia/student_version/                 
http://www.mathworks.com/products/                                 
http://www.mathworks.com/products/matlab/index.shtml               
http://www.mathworks.com/index.html?ref=logo                       
http://www.mathworks.com/matlabcentral/fileexchange/               
http://www.mathworks.com/matlabcentral/                            
http://www.indiana.edu/~statmath/math/matlab/                      
http://www.mines.utah.edu/gg_computer_seminar/matlab/matlab.html   
http://www.mathworks.com/support/                                  
http://www.mathworks.com/access/helpdesk/help/techdoc/             
http://www.mathworks.com/products/product_listing/                 
http://www.mathworks.com/products/matlab/requirements.html         
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ref.shtml
http://www-ccs.ucsd.edu/matlab/                                    
http://www.engin.umich.edu/group/ctm/                              
http://en.wikipedia.org/wiki/Matlab                                
http://en.wikipedia.org/wiki/MATLAB                                
disp(s.EstimatedTotalResultsCount)
    28700000

for i = 1:s.EndIndex
    % Strip HTML from the title.
    title = s.ResultElements(i).Title;
    title = regexprep(title,'<\/?b>','');
    title = strrep(title,'&gt;','>');
    title = strrep(title,'&lt;','<');
    title = regexprep(title,'&#(\d+);','${char(str2double($1))}');
    title = strrep(title,'&amp;','&');

    % Display the title and URL for each page.
    fprintf('%4.0f) %s\n      %s\n\n', ...
        i,title,s.ResultElements(i).URL)
end
   1) The MathWorks - MATLAB and Simulink for Technical Computing
      http://www.mathworks.com/

   2) MATLAB
      http://www.mathworks.com/products/matlab/

   3) MATLAB
      http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.shtml

   4) The MathWorks - Online Documentation, R2006a
      http://www.mathworks.com/access/helpdesk/help/helpdesk.html

   5) MATLAB
      http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.html

   6) The MathWorks - Academia
      http://www.mathworks.com/academia/

   7) Matlab
      http://www.math.utah.edu/lab/ms/matlab/matlab.html

   8) MATLAB Summary and Tutorial
      http://www.math.ufl.edu/help/matlab-tutorial/

   9) Matlab Primer
      http://math.ucsd.edu/~driver/21d-s99/matlab-primer.html

  10) A Practical Introduction to MATLAB
      http://www.math.mtu.edu/~msgocken/intro/intro.html

  11) Mathtools.net : MATLAB
      http://www.mathtools.net/MATLAB/index.html

  12) Mathtools.net
      http://www.mathtools.net/

  13) MATLAB
      http://www.mathworks.co.uk/products/matlab

  14) The MathWorks - Student Version - MATLAB Student Version
      http://www.mathworks.com/academia/student_version/

  15) The MathWorks - Products & Services
      http://www.mathworks.com/products/

  16) The MathWorks - MATLAB® - The Language of Technical Computing
      http://www.mathworks.com/products/matlab/index.shtml

  17) The MathWorks - MATLAB and Simulink for Technical Computing
      http://www.mathworks.com/index.html?ref=logo

  18) The MathWorks - MATLAB Central - File Exchange
      http://www.mathworks.com/matlabcentral/fileexchange/

  19) MATLAB Central
      http://www.mathworks.com/matlabcentral/

  20) Matlab - Indiana University
      http://www.indiana.edu/~statmath/math/matlab/

  21) Matlab Tutorial
      http://www.mines.utah.edu/gg_computer_seminar/matlab/matlab.html

  22) The MathWorks - Support
      http://www.mathworks.com/support/

  23) MATLAB
      http://www.mathworks.com/access/helpdesk/help/techdoc/

  24) The MathWorks - Product Listing - Products by Category
      http://www.mathworks.com/products/product_listing/

  25) The MathWorks - MATLAB® 7.2 - Requirements
      http://www.mathworks.com/products/matlab/requirements.html

  26) MATLAB Functions
      http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ref.shtml

  27) MATLAB Help Desk
      http://www-ccs.ucsd.edu/matlab/

  28) Control Tutorials for MATLAB
      http://www.engin.umich.edu/group/ctm/

  29) MATLAB - Wikipedia, the free encyclopedia
      http://en.wikipedia.org/wiki/Matlab

  30) MATLAB - Wikipedia, the free encyclopedia
      http://en.wikipedia.org/wiki/MATLAB

Opening Up a Web Page

Use FEELINGLUCKY to jump straight to the first hit for "MathWorks".

feelinglucky MathWorks