23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6 Data Import and Export<br />

urlread('http://www.mathworks.com/matlabcentral/fileexchange/<br />

loadFileList.do?objectType=fileexchange&orderBy=date&srt3=0');<br />

% The strfind function searches for the word "Simulink".<br />

hits = strfind(recentFile,'Simulink');<br />

% The if statement checks for any hits.<br />

if ~isempty(hits)<br />

% If there are hits, the Web page will be saved locally<br />

% using the urlwrite function.<br />

urlwrite('http://www.mathworks.com/matlabcentral/fileexchange/<br />

loadFileList.do?objectType=fileexchange&orderBy=date&srt3=0',<br />

'contains_simulink.html');<br />

end;<br />

<strong>MATLAB</strong> saves the Web page as contains_simulink.html.<br />

Creating and Decompressing Zip Archives<br />

Using the zip and unzip functions, you can compress and decompress files<br />

and directories. The zip function compresses files or directories into a zip<br />

archive. The unzip function decompresses zip archives.<br />

Example — Using the zip Function<br />

Again building on the example from previous sections, the following code<br />

creates a zip archive of the retrieved Web page:<br />

% The urlread function loads the contents of the Web page into<br />

the % <strong>MATLAB</strong> workspace.<br />

recentFile =<br />

urlread('http://www.mathworks.com/matlabcentral/fileexchange/<br />

loadFileList.do?objectType=fileexchange&orderBy=date&srt3=0');<br />

% The strfind function searches for the word "Simulink".<br />

hits = strfind(recentFile,'Simulink');<br />

% The if statement checks for any hits.<br />

if ~isempty(hits)<br />

6-118

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!