MATLAB Programming
MATLAB Programming MATLAB Programming
6 Data Import and Export Loading Binary Data MAT-files are double-precision binary MATLAB format files created by the save function and readable by the load function. They can be created on one machine and later read by MATLAB on another machine with a different floating-point format, retaining as much accuracy and range as the different formats allow. They can also be manipulated by other programs, external to MATLAB. MAT-filescancontaindatainanuncompressedoracompressedform,orboth. MATLAB knows which variables in the file have been compressed by looking at a tag that it attaches to each variable during the save operation. When loading data from a MAT-file into the workspace, MATLAB automatically handles the decompression of the appropriate data. The External Interface libraries contain C- and Fortran-callable routines to read and write MAT-files from external programs. Loading ASCII Data ASCII files must be organized as a rectangular table of numbers, with each number in a row separated by a blank, comma, or tab character, and with an equal number of elements in each row. MATLAB generates an error if the number of values differs between any two rows. ASCII files can contain MATLAB comments (lines that begin with %). MATLAB returns all the data in the file as a single two-dimensional array of type double. The number of rows in the array is equal to the number of lines in the file, and the number of columns is equal to the number of values on a line. In the workspace, MATLAB assigns the array to a variable named after the file being loaded (minus any file extension). For example, the command load mydata.dat reads all of the data from mydata.dat into the MATLAB workspace as a single array, and assigns it to a variable called mydata. Innamingthevariable,load precedes any leading underscores or digits in filename with an X and replaces any other nonalphabetic characters with underscores. 6-32
Saving and Loading MAT-Files For example, the command load 10-May-data.dat assigns the data in file 10-May-data.dat to a new workspace variable called X10_May_data. 6-33
- 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 464 and 465: 6 Data Import and Export Data Compr
- Page 466 and 467: 6 Data Import and Export Preference
- Page 468 and 469: 6 Data Import and Export Saving fro
- 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
- Page 514 and 515: 6 Data Import and Export character.
- Page 516 and 517: 6 Data Import and Export Table6-2 A
- Page 518 and 519: 6 Data Import and Export A = dlmrea
Saving and Loading MAT-Files<br />
For example, the command<br />
load 10-May-data.dat<br />
assigns the data in file 10-May-data.dat to a new workspace variable called<br />
X10_May_data.<br />
6-33