MATLAB® provides two functions for reading content from
RESTful web services:
websave. With the
you can read the contents of a web page to a character array in the MATLAB workspace.
websave function, you can save web page
content to a file.
Because it can create a character array in the workspace, the
is useful for working with the contents of web pages in MATLAB.
websave function is useful for saving web
pages to a local folder.
webread returns HTML as a character
array, remember that only the HTML in that specific web page is retrieved.
The hyperlink targets, images, and so on, are not retrieved.
If you need to pass parameters to a web page, the
let you define the parameters as
Name, Value pair
arguments. For more information, see the
The following procedure demonstrates how to retrieve the contents of the web page listing the
files submitted to the MATLAB
https://www.mathworks.com/matlabcentral/fileexchange/. It assigns the results to a character array,
filex = 'https://www.mathworks.com/matlabcentral/fileexchange/'; fullList = webread(filex);
Retrieve a list of only those files uploaded to the File Exchange
within the past seven days that contain the word Simulink®. Set
webread passes to the web page.
filex = 'https://www.mathworks.com/matlabcentral/fileexchange/'; recent = webread(filex,'duration',7,'term','simulink');
The following example builds on the procedure in the previous section, but saves the content to a file:
% Locate the list of files at the MATLAB Central File Exchange % uploaded within the past 7 days, that contain "Simulink." filex = 'https://www.mathworks.com/matlabcentral/fileexchange/'; % Save the Web content to a file. recent = websave('contains_simulink.html',filex, ... 'duration',7,'term','simulink');
MATLAB saves the web page as
The output argument
recent contains the full path
contains_simulink.html. Call the
contains_simulink.html in a browser.
This page has links to files uploaded to the MATLAB Central File Exchange.