23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6 Data Import and Export<br />

type =<br />

Microsoft Excel Spreadsheet<br />

sheets =<br />

'Locations' 'Rainfall' 'Temperatures'<br />

Exporting to the File<br />

Use the xlswrite function to export a matrix to an Excel spreadsheet file.<br />

With xlswrite, you can export data from the workspace to any worksheet in<br />

the file, and to any location within that worksheet.<br />

Inputs to xlswrite are<br />

• Name of the spreadsheet file<br />

• Matrix to be exported<br />

• Name of the worksheet to receive the data<br />

• Rangeofcellsontheworksheetinwhichtowritethedata<br />

Outputs from xlswrite are<br />

• Pass or fail status<br />

• Any warning or error message generated along with its message identifier<br />

Example — Writing To an XLS File. This example writes a mix of text and<br />

numeric data to the file tempdata.xls. Callxlswrite, specifying a worksheet<br />

labeled Temperatures, and the region within the worksheet to write the data<br />

to. The 4-by-2 matrix is written to the rectangular region that starts at cell E1<br />

in its upper-left corner:<br />

d = {'Time', 'Temp'; 12 98; 13 99; 14 97}<br />

d =<br />

'Time' 'Temp'<br />

[ 12] [ 98]<br />

[ 13] [ 99]<br />

[ 14] [ 97]<br />

xlswrite('tempdata.xls', d, 'Temperatures', 'E1');<br />

6-98

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

Saved successfully!

Ooh no, something went wrong!