MATLAB has two types of file composition:1. File (m file);2. data file . opening and closing of files
File data formats are: binary format and text file . Open the file
FID = fopen (file name, open mode);
' R ': Indicates read data for open file.
' W ': Indicates write data to open file.
' A ': Indicates that data is added at the end of an open file. Closing of files
Sta-fclose (Fid); Turn off read and write operations of the file files represented by the FID to read and write operations of the binary file
[A, Count] = fread (FID, size, precision); % read
Precision represents the type of read and write data.
Count = fwrite (FID, A, precision); % Write
FID = fopen (' Magic5.dat ', ' W '); % Create Magic5.dat file
cnt = fwrite (FID, Magic (5), ' Int32 '); 5 order Magic Phalanx is stored in the file
fclose (FID);
FID = fopen (' Magic5.dat ', ' R '); % Open Magic5.dat
[B, cnt] = Fread (fid,[5,5], ' int32 ');% the data in the function handle is read out and deposited in matrix B
fclose (FID);
b % output matrix B
text File
[A,count] = fscanf (Fid, format, size);
Format is used to control read data formats, which are composed of % plus format characters:
d, I, O, u, x, E, F, G, S, C and [...]
Note: Similar to the C language
Count = fprintf (Fid, format, A, ...); MATLAB Data Interface
Mat file.
Data storage:Save command
MATLAB system Internal data can be written as Mat file
The default is stored in binary format. If ASCII code is required, add-ascii
How to invoke the Save command: Save : All variables in the workspace are stored in binary form in Matlab.mat; Save FileName: store All the variables in the workspace in binary form in Filename.mat; save filename variables: Variables the specified variable of the workspace in binary form in Filename.mat; save filename Options: stores all the variables for the workspace in the format in the following table. Save filename Variables options: stores the specified variables for the workspace using the format in the following table.
Data input:load instruction to import the mat data file stored on disk into MATLAB workspace. calls to MATLAB and Excel data
xlswrite Writing to Excel
Xlsread Reading Excel