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

or save just those variables that you specify:<br />

save filename var1 var2 ... varN<br />

Usethewildcardcharacter(*)inthevariablenametosavethosevariables<br />

that match a specific pattern. For example, the following command saves all<br />

variables that start with str.<br />

save strinfo str*<br />

Use whos -file to examine what has been written to the MAT-file:<br />

whos -file strinfo<br />

Name Size Bytes Class<br />

str2 1x15 30 char array<br />

strarray 2x5 678 cell array<br />

strlen 1x1 8 double array<br />

Saving Structures<br />

When saving a <strong>MATLAB</strong> structure, you have the option of saving the entire<br />

structure, saving each structure field as an individual variable in the<br />

MAT-file, or saving specific fields as individual variables.<br />

For structure S,<br />

S.a = 12.7; S.b = {'abc', [4 5; 6 7]}; S.c = 'Hello!';<br />

Save the entire structure to newstruct.mat with the usual syntax:<br />

save newstruct.mat S;<br />

whos -file newstruct<br />

Name Size Bytes Class<br />

S 1x1 550 struct array<br />

Save the fields individually with the -struct option:<br />

save newstruct.mat -struct S;<br />

6-24

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

Saved successfully!

Ooh no, something went wrong!