MATLAB file operation

Source: Internet
Author: User
Tags fread

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.