Fortune Telling Collection - Comprehensive fortune-telling - Matlab fortune-telling command _matlab calculation command
Matlab fortune-telling command _matlab calculation command
MATLAB file operation related commands
Input and output statements
(1) real-time interactive input and output
Input; keyboard
(2) Full copy file access
* 1) save
rescue
Save "file name" x
Save the file name x y z
Save the file name x y z -ascii.
Save the file name x y z -ascii -double.
Save the file name x y z-ascii- double tab.
Save "existing file name" x y z attachment
Note 1: The saved default file name is fname.m
Note 2:–ASCII 8-byte ASCII code mode
Note 3:–ASCII16 byte ASCII code mode
Note 3:–ASCII–Double Tab Format Arrangement
Note 3:–Append is stored after continuation.
*2) Load
load
Load "file name"
Note that the default file name of 1:load is fname.m
(3) file access management (creation, reading and writing)
File management (open, write, read, close, locate),
*1) "fopen" opens the file and gives it a code.
Syntax 1: FID = fopen (file name, permission)
Open the file in the specified way.
FID=+N(N is a positive integer): indicates that the file was opened successfully, and the file code is n. 。
FID=- 1: indicates that the file was not opened successfully.
FID is always valid until this file is closed.
If it is opened by reading, matlab will search the working directory first, and then search other directories of matlab. Permission is an open mode parameter.
The open mode parameters are determined by the following string:
R reading
Write (if the file does not exist, it will be created automatically)
Subsequent writes (if the file does not exist, it will be created automatically)
R+ read and write (file should already exist)
W+ refresh write, (if the file does not exist, it will be created automatically)
A+ Subsequent writes (automatically created if the file does not exist))
W rewritten, but not automatically refreshed.
A Subsequent writes, but no automatic refresh.
File storage format: The default way to open files is binary. Open as text, you can use the method parameter.
For example, adding the "t" file to the number "permission" would be "rt" and "wt+".
Syntax 2: [FID, message] = fopen (file name, permission)
FID=- 1, when the file is not opened successfully, an error message is returned.
Syntax 3: [FID, message] = fopen (file name, permission, machine format)
Permission: Open the file in the specified way.
Machineformat: specifies the data format used for reading and writing.
The data format (machine format) values are as follows
"Native" or "n" local machine format-default
Ieee-le' or' l' IEEE floating-point number (little endian sorting)
"Ieee-be" or "B" IEEE floating-point number (big endian sorting)
"Vaxd" or "Vaxd floating point number (VAX order)
"Vaxg" or "Vaxg floating point number (VAX order)
"Cray" or "C" Cray floating point number (big endian sort)
Long data
Ieee-le.l64' or' a' IEEE floating-point number (little endian sorting and 64 bits)
Long data type
Iecc-be.l64' or' s' IEEE floating-point number (big byte sort and 64 bits)
Long data width
Syntax 4:[ file name, authority, machine format ]=fopen(fid).
View file opening and return file name, opening method and file format. If fid does not exist, a variable is returned.
fid=fopen('allall ')
Returns all currently open files.
* 2) "fwrite" writes data to a file in binary form.
Syntax 1: count = fwrite (fid, a, precision)
Write the matrix a into the open file pointed by fid, and matlab will automatically convert the value of a into the precision specified by Precision (see below) and write it in the form of columns. Count is the return value. If the writing is successful, the number of data written is returned, otherwise, 0 is returned.
Syntax 2: count = fwrite (FID, a, precision, skip)
Skip: take a positive integer n,
Write the matrix a into the open file pointed by fid with the jump value of step n, for example, a= 1, 2, 3, 4, 5, 6, 7, 8, 9; skip = 2; Then enter _, _, 3, _, _, 6, _, _, 9. This is significant for discontinuous data fields and fixed-length inserted data.
* 3) "FREAD" reads data from a file in binary form.
Syntax 1: [a, count] = fread (FID, size, precision)
Syntax 2: [a, count] = fread (FID, size, precision, skip)
Size: Unspecified: Returns reading from beginning to end.
N: read n data to form a column vector.
Inf: Read all the data of the open file pointed by fid.
[M, N]: read n data to form a column vector and fill in the M*N matrix.
Accuracy (Precision)
Precision specifies the number of bytes when reading floating-point numbers, integers and characters. The precision expression of matlab is consistent with C language and fortran language. If precision is not specified, the character defaults to: ucher and the value defaults to: double precision.
The following accuracy will ensure that the readings have a consistent volume.
MATLAB C or Fortran descriptor (precision)
Char' 'char*l' 8 bytes, character type
Uchar'' unsigned character' 8 bytes
Schar'' signed character'' 8 bytes, character type
Int8' 'integer* 1' 8 bytes, integer
Intl6' 'integer*2' 16 bytes, integer.
Int32' 'integer*4' 32 bytes, integer.
Int64' 'integer*8' 64 bytes, integer.
Uint8'' integer *l' 8 bytes
Uintl6' 'integer*2' 16 bytes
Uint32'' Integer *4' 32 bytes
Uint64'' Integer *8' 64 bytes
Float32' 'real*4'' floating point number, 32 bytes.
Float64' 'real*8'' floating point number, 32 bytes.
The following accuracy does not guarantee that the readings have a consistent volume.
MATLAB C or Fortran descriptor (precision)
Short' 'short' 16 bytes, integer
Int' 'int' 32 bytes, integer
Long' 'long' 32 (64) bytes, integer
Usport'' unsigned short integer' 16 bytes.
Uint'' unsigned integer'' 32 bytes
Ulong'' unsigned long integer' 32 (64) bytes
Float' 'float' floating point number, 32 bytes.
Double' 'double' floating point number, 64 bytes.
The following precision specifies reading the specified volume n.
BitN' N bytes, integer 1
Ubitrn' n bytes, 1
*4) Read the data in fscanf format from the file.
Grammar 1: [a, count] = fscanf (FID, format, size)
According to the specified format, read data from fid file in format format and store it in memory in size format.
A: variable name of data read into memory.
Count: Return value. 0: failure, n>0: success, n is the number of times to read data.
Fid: document number
Size: the format of the data.
N: column vector
Inf: Read all the data of the file.
[M, N]: put the read data into the variable name a in the format of m * n.
Format: the format of reading data.
Format is a character form, which is basically the same as C language. There are "%"in character form and character set (D, I, O, U, X, E, F, G, S, C, ...).
Such as: %s: single character reading
%c: read space characters
Example: s=fscanf(fid,' %s') returns a character.
A=fscanf(fid,' %5d') returns a five-digit decimal integer.
*5) Close the file fclose
Grammar 1: fclose (FID)
Syntax 2: fclose ('all')
*6) Write data into the file printf.
Syntax 1: count = printf (FID, format, a, b, s, ...)
Example:
x = 0:0. 1: 1;
y =[x; exp(x)];
fid=fopen('exp.txt ',' w ')
fprintf(fid,' %6.2 % 12.8f\n ',y);
Calculation result:
0.0 1.00000000
0. 1 1. 105 17092
1.00 2.7 1828 183
*8) Put the pointer in the file header: frewind
Grammar 1: Frewind (FID)
Hans-font-family:' New Romance of the Times'; MSO-ascii-font-family:' Times New Roman ' " & gt; The following precision specifies reading the specified volume n.
BitN' N bytes, integer 1
Ubitrn' n bytes, 1
*4) Read the data in fscanf format from the file.
Grammar 1: [a, count] = fscanf (FID, format, size)
According to the specified format, read data from fid file in format format and store it in memory in size format.
A: variable name of data read into memory.
Count: Return value. 0: failure, n>0: success, n is the number of times to read data.
Fid: document number
Size: the format of the data.
N: column vector
Inf: Read all the data of the file.
[M, N]: put the read data into the variable name a in the format of m * n.
Format: the format of reading data.
Format is a character form, which is basically the same as C language. There are "%"in character form and character set (D, I, O, U, X, E, F, G, S, C, ...).
Such as: %s: single character reading
%c: read space characters
Example: s=fscanf(fid,' %s') returns a character.
A=fscanf(fid,' %5d') returns a five-digit decimal integer.
*5) Close the file fclose
Grammar 1: fclose (FID)
Syntax 2: fclose ('all')
*6) Write data into the file printf.
Syntax 1: count = printf (FID, format, a, b, s, ...)
Example:
x = 0:0. 1: 1;
y =[x; exp(x)];
fid=fopen('exp.txt ',' w ')
fprintf(fid,' %6.2 % 12.8f\n ',y);
Calculation result:
0.0 1.00000000
0. 1 1. 105 17092
1.00 2.7 1828 183
*8) Put the pointer in the file header: frewind
Grammar 1: Frewind (FID)
- Previous article:Requirements for learning fortune telling
- Next article:What is a fortune teller _ What does a fortune teller mean?
- Related articles
- What does the temple mean? What are synonyms and antonyms? What is English translation?
- Download the complete works of txt for free.
- Free fortune-telling in 2022 _ Free fortune-telling fortune
- I dreamed that my boyfriend told me that I had bad breath.
- Where is there a fortune teller in Ji 'an, Jiangxi _ Where is there a fortune teller in Ji 'an, Jiangxi?
- How should the chess game start?
- The plot of the TV series Xianjian 3
- Where is ASUS mobile phone repaired in Shunqing District, Nanchong?
- What are the customs of getting married in Tuanbei?
- Auspicious days of the zodiac, you can query the yellow calendar, auspicious days of the zodiac, and you can query the perpetual calendar.