MATLAB Programming

MATLAB Programming MATLAB Programming

cda.psych.uiuc.edu
from cda.psych.uiuc.edu More from this publisher
23.06.2015 Views

6 Data Import and Export Import from text file grades.txt, using default variables to store the data: uiimport grades.txt whos Name Size Bytes Class Attributes data 4x3 96 double rowheaders 4x1 272 cell textdata 4x1 272 cell Example 2—Partial Text File with Row Vectors. Import from the same file as in the above example, but this time select Create vectors from each row using row names. Also, clear the checkbox next to variable John so that this one vector does not get written to the workspace: whos Name Size Bytes Class Attributes Ann 1x3 24 double Martin 1x3 24 double Rob 1x3 24 double Example 3—Binary Data Assigned to a Structure. Save numeric and text data in binary format in file importtest.mat and use the Import Wizard toimportthebinaryfileintotheworkspace. C = [1 2 3 4 5;6 7 8 9 10]; D = 'a test string'; save importtest C D clear s = uiimport('importtest.mat') s = C: [2x5 double] D: 'a test string' 6-20

Supported File Formats Supported File Formats The table below shows the file formats that you can read or write from MATLAB along with the functions that support each format. File Format File Content Extension Functions MATLAB formatted Text Extended Markup Language Saved MATLAB workspace .mat load, save Text any textscan Text any textread Delimited text any dlmread, dlmwrite Comma-separated numbers .csv csvread, csvwrite XML-formatted text .xml xmlread, xmlwrite Audio NeXT/SUN sound .au auread, auwrite Microsoft WAVE sound .wav wavread, wavwrite Movie Audio/video .avi aviread Scientific data Spreadsheet Data in Common Data Format Flexible Image Transport System data Data in Hierarchical Data Format .cdf .fits .hdf cdfread, cdfwrite fitsread hdfread Excel worksheet .xls xlsread, xlswrite Lotus 123 worksheet .wk1 wk1read, wk1write 6-21

6 Data Import and Export<br />

Import from text file grades.txt, using default variables to store the data:<br />

uiimport grades.txt<br />

whos<br />

Name Size Bytes Class Attributes<br />

data 4x3 96 double<br />

rowheaders 4x1 272 cell<br />

textdata 4x1 272 cell<br />

Example 2—Partial Text File with Row Vectors. Import from the same<br />

file as in the above example, but this time select Create vectors from each<br />

row using row names. Also, clear the checkbox next to variable John so that<br />

this one vector does not get written to the workspace:<br />

whos<br />

Name Size Bytes Class Attributes<br />

Ann 1x3 24 double<br />

Martin 1x3 24 double<br />

Rob 1x3 24 double<br />

Example 3—Binary Data Assigned to a Structure. Save numeric and<br />

text data in binary format in file importtest.mat and use the Import Wizard<br />

toimportthebinaryfileintotheworkspace.<br />

C = [1 2 3 4 5;6 7 8 9 10];<br />

D = 'a test string';<br />

save importtest C D<br />

clear<br />

s = uiimport('importtest.mat')<br />

s =<br />

C: [2x5 double]<br />

D: 'a test string'<br />

6-20

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

Saved successfully!

Ooh no, something went wrong!