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 />

number of output variables must match the number of conversion specifiers<br />

in the format string.<br />

In this example, textread reads the file mydata.dat, applying the format<br />

string to each line in the file until the end of the file:<br />

[names, types, x, y, answer] = ...<br />

textread('mydata.dat', '%s %s %f %d %s', 3)<br />

names =<br />

'Sally'<br />

'Larry'<br />

'Tommy'<br />

types =<br />

'Type1'<br />

'Type2'<br />

'Type1'<br />

x =<br />

12.3400<br />

34.5600<br />

67.8900<br />

y =<br />

45<br />

54<br />

23<br />

answer =<br />

'Yes'<br />

'Yes'<br />

'No'<br />

If your data uses a character other than a space as a delimiter, you must use<br />

the textread parameter 'delimiter' to specify the delimiter. For example,<br />

if the file mydata.dat used a semicolon as a delimiter, you would use this<br />

command:<br />

[names, types, x, y, answer]= ...<br />

textread('mydata.dat', '%s %s %f %d %s', 'delimiter', ';')<br />

6-82

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

Saved successfully!

Ooh no, something went wrong!