MATLAB Programming
MATLAB Programming MATLAB Programming
6 Data Import and Export Data Compression MATLAB compresses the data that you savetoaMAT-file.Datacompression can save you a significant amount of storage space when you are working with large files or working over a network. Data compression is optional, however, and you can disable it either for an individual save operation, or for all of your MATLAB sessions. Use the -v6 option with the save function to turn off compression on a per-command basis: save filename -v6 To disable data compression for all of your MATLAB sessions, open the Preferences dialog, select General and then MAT-Files, and click the option that is equivalent to the command save -v6. See General Preferences for MATLAB in the Desktop Tools and Development Environment documentation for more information. Note You cannot read a compressed MAT-file with MATLAB versions earlier thanVersion7.TowriteaMAT-filethatyouwillbeabletoreadwithoneof these versions, save to the file with data compression disabled. Information returned by the command whos -file is independent of whether the variables in that file are compressed or not. The byte counts returned by this command represent the number of bytes data occupies in the MATLAB workspace, and not in the file the data was saved to. Evaluating When to Compress. You should consider both data set size and the type of data being saved when deciding whether or not to compress the data you save to a file. The benefits of data compression are greater when saving large data sets (over 3 MB), and are usually negligible with smaller data sets. Data that has repeating patterns or more consistent values compresses better than random data. Compressing data that has a random pattern is not recommended as it slows down the performance of save and load significantly, and offers little benefit in return. In general, data compression and decompression slows down all save and some load operations to some extent. In most cases, however, the resulting reductioninfilesizeisworththeadditional time spent compressing or 6-26
Saving and Loading MAT-Files decompressing. Because loading is typically done more frequently than saving, load is considered to be the most critical of the two operations. Up to a certain threshold (relative to the size of the uncompressed MAT-file), loading a compressed MAT-File is slightly slower than loading an uncompressed file containing the same data. Beyond that threshold, however, loading the compressed file is faster. For example, say that you have a block of data that takes up 100 MB in memory, and this data has been saved to both a 10 MB compressed file and a 100 MB uncompressed file. When you load each of these files back into the MATLAB workspace, the first 10 MB of data takes the same amount of time to load for each file. Loading the remaining 90 MB from the uncompressed file will take 9 times as long as the first 10 MB, while all that remains to be done with the compressed file is to decompress the data, and this takes a relatively short amount of time. The loading size threshold is lower for network files, and also varies depending on the type of computer being used. Network users loading compressed MAT-files generally see faster load times than when loading uncompressed files, and at smaller data sizes than users loading the same files locally. Note Compression and decompression during save and load is done transparently without the use of temporary files on disk. This is of significance to large dataset users in particular. Unicode Character Encoding MATLAB saves character data to a MAT-file using Unicode character encoding. As with data compression, Unicode character encoding is optional. If you disable it, MATLAB writes the MAT-file using the default encoding for your system. To disable Unicode character encoding on a per-command basis, use the -v6 option with the save function: save filename -v6 To disable Unicode character encoding for all of your MATLAB sessions, open the Preferences dialog, select General and then MAT-Files, and click the option that is equivalent to the command save -v6. SeeGeneral 6-27
- Page 414 and 415: 5 Types of Functions Supply the val
- Page 416 and 417: 5 Types of Functions Nested Functio
- Page 418 and 419: 5 Types of Functions • From a fun
- Page 420 and 421: 5 Types of Functions not shared bet
- Page 422 and 423: 5 Types of Functions You can now us
- Page 424 and 425: 5 Types of Functions Using a Subfun
- Page 426 and 427: 5 Types of Functions count = 125 22
- Page 428 and 429: 5 Types of Functions shape. The mak
- Page 430 and 431: 5 Types of Functions % FILTFCN. Eac
- Page 432 and 433: 5 Types of Functions 0.6667 filt2(1
- Page 434 and 435: 5 Types of Functions unless you dec
- Page 436 and 437: 5 Types of Functions Accessing Help
- Page 438 and 439: 5 Types of Functions 5-38
- Page 440 and 441: 6 Data Import and Export Working wi
- Page 442 and 443: 6 Data Import and Export • “Dat
- Page 444 and 445: 6 Data Import and Export file that
- Page 446 and 447: 6 Data Import and Export Function r
- Page 448 and 449: 6 Data Import and Export Importing
- Page 450 and 451: 6 Data Import and Export • rowhea
- Page 452 and 453: 6 Data Import and Export File to im
- Page 454 and 455: 6 Data Import and Export Example of
- Page 456 and 457: 6 Data Import and Export was select
- Page 458 and 459: 6 Data Import and Export Import fro
- Page 460 and 461: 6 Data Import and Export File Forma
- Page 462 and 463: 6 Data Import and Export or save ju
- Page 466 and 467: 6 Data Import and Export Preference
- Page 468 and 469: 6 Data Import and Export Saving fro
- Page 470 and 471: 6 Data Import and Export Loading Bi
- Page 472 and 473: 6 Data Import and Export Accessing
- Page 474 and 475: 6 Data Import and Export Sharing Me
- Page 476 and 477: 6 Data Import and Export • For sm
- Page 478 and 479: 6 Data Import and Export Note Prope
- Page 480 and 481: 6 Data Import and Export Writable:
- Page 482 and 483: 6 Data Import and Export Ifthefilet
- Page 484 and 485: 6 Data Import and Export For exampl
- Page 486 and 487: 6 Data Import and Export m = memmap
- Page 488 and 489: 6 Data Import and Export Mapping of
- Page 490 and 491: 6 Data Import and Export Repeating
- Page 492 and 493: 6 Data Import and Export Note To su
- Page 494 and 495: 6 Data Import and Export d = m.Data
- Page 496 and 497: 6 Data Import and Export ans = 166x
- Page 498 and 499: 6 Data Import and Export If you hav
- Page 500 and 501: 6 Data Import and Export m.Data(60)
- Page 502 and 503: 6 Data Import and Export m = memmap
- Page 504 and 505: 6 Data Import and Export d = m.Data
- Page 506 and 507: 6 Data Import and Export Data: 1658
- Page 508 and 509: 6 Data Import and Export One MATLAB
- Page 510 and 511: 6 Data Import and Export disp('ANSW
- Page 512 and 513: 6 Data Import and Export Terminatin
Saving and Loading MAT-Files<br />
decompressing. Because loading is typically done more frequently than<br />
saving, load is considered to be the most critical of the two operations. Up to a<br />
certain threshold (relative to the size of the uncompressed MAT-file), loading<br />
a compressed MAT-File is slightly slower than loading an uncompressed<br />
file containing the same data. Beyond that threshold, however, loading the<br />
compressed file is faster.<br />
For example, say that you have a block of data that takes up 100 MB in<br />
memory, and this data has been saved to both a 10 MB compressed file and a<br />
100 MB uncompressed file. When you load each of these files back into the<br />
<strong>MATLAB</strong> workspace, the first 10 MB of data takes the same amount of time<br />
to load for each file. Loading the remaining 90 MB from the uncompressed<br />
file will take 9 times as long as the first 10 MB, while all that remains to be<br />
done with the compressed file is to decompress the data, and this takes a<br />
relatively short amount of time.<br />
The loading size threshold is lower for network files, and also varies depending<br />
on the type of computer being used. Network users loading compressed<br />
MAT-files generally see faster load times than when loading uncompressed<br />
files, and at smaller data sizes than users loading the same files locally.<br />
Note Compression and decompression during save and load is done<br />
transparently without the use of temporary files on disk. This is of<br />
significance to large dataset users in particular.<br />
Unicode Character Encoding<br />
<strong>MATLAB</strong> saves character data to a MAT-file using Unicode character<br />
encoding. As with data compression, Unicode character encoding is optional.<br />
If you disable it, <strong>MATLAB</strong> writes the MAT-file using the default encoding for<br />
your system. To disable Unicode character encoding on a per-command basis,<br />
use the -v6 option with the save function:<br />
save filename -v6<br />
To disable Unicode character encoding for all of your <strong>MATLAB</strong> sessions,<br />
open the Preferences dialog, select General and then MAT-Files, and<br />
click the option that is equivalent to the command save -v6. SeeGeneral<br />
6-27