In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to carry out MATLAB fread function analysis, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
MATLAB is really convenient to use, as long as you know its functions.
The help document of MATLAB is called a seemingly unintelligible document, which is hereby summarized. For me, the main form of invocation of fread is as follows:
Data = fread (fid, N, 'str')
Needless to say, fid is naturally a file handle (such as fid=fopen ('abc.txt',' r'), N is the number of elements read in, and 'str' is the format. When the format is omitted directly when it is not previously used, the function reads the data from the file byte by byte and converts it into double form in MATLAB.
If the file is a binary file, of course it's okay to read it this way, but not if you want to read text. The text is also read byte by byte, but should eventually be converted to char:
> > frewind (f); > > a=fread (fmae1fuchar = > char') a = B > > frewind (f); > > a=fread (fmae1phiuchar = > uchar') a = 66 > > class (a) ans = uint8 > > frewind (f); > a=fread (fmine1pimuint8 = > char') a = B > > frewind (f); > a=fread (fmae1fuchar = > char') a = B > frewind (f); > a=fread (fmine1pimuint8 = > char') a = B
The above is an example of a BMP file, which reads the first byte of the file, the BMP file begins with "BM", and the first one is naturally B. Int8, uint8, char, and uchar are several one-byte data types. In the example, a = > b indicates that it is read as a type and then converted to b type. The function of an is to control the number of bytes read each time, and then convert it to the corresponding type to form a certain numerical value, and the function of b is to convert it on the basis of a. Here is a byte, after reading, finally if it is chartype, it becomes the letter B, if it is uchar type, it becomes uint8.
The above is an example of the same number of bytes. A = > b _ a does not seem to be of much use, but when the number of bytes is different, it is very useful:
> > frewind (f) > > a=fread (frecinct 16 = > uint8') a = 255% here, uint16 is two bytes, so read 2 bytes at a time, first read in the form of uint16, the arrangement of integers is very simple. If the low byte is a, and the high byte is b, then it is equal to bend256. The resulting number must be more than 256a, and finally it has to be converted into uint8, so we can only truncate uint8 one byte, and the maximum number that can be expressed is 255mm. So return 255.
> > frewind (f); > > a=fread (fjin1gramuint16 = > float') a = 19778% here, it shows that the number read by uint16 is 19778, and then converted to a single-precision float type, which is still 19778. Of course, the type has been replaced > > frewind (f); > > a=fread (fjin1gramuint32') a = 37637442 * uint32 is equivalent to uint32= > uint32, which is read in the form of 4 bytes and becomes an integer. > > frewind (f); > > a=fread (fjin1 dint 32 = > float') a = 37637440% is read in the form of four bytes, first becomes an integer, then becomes float, and the last 2 is lost. Is it a problem of accuracy? > > class (a) ans = single
> > frewind (f); > > a=fread (fMagne1 levuint32 = > double') a = 37637442% is converted to double, and the precision is enough > > frewind (f); > > a=fread (fmage1gramme float = > double') a = 1.3981eRue 037% the most exciting thing is that although both float and uint32 are 4 bytes, the number obtained here is not equal to the above. As mentioned earlier, a = > b, the system reads the corresponding number of bytes in a format, converts it into a value of type a, and then converts an into type b. When reading here, it is read according to the rules of float, and then float is converted into double, which is nothing more than to improve accuracy. > > frewind (f); > > a=fread (fMagne1 recording float = > uint32') a = 0% reads 1.3981e-037, which is converted to an integer, which is 0 of course
In addition, I have tried the following formats:
> > a=fread (frecinct 1 recording int8 = > char') a = B
The form of skip = > b is usually used where there is a skip, which is not specified in the following parameters, so the default skip is zero, and the result is the letter B. Skipping forms are often used when you press bit to read
> > a=fread = 66 77 62 > > frewind (f) > > a=fread = 66 62 20% Note: press int8 when you read it before, so when you skip it, you skip the length of 1 int8, so you skip 77, and the result is 6 6 int8 62 > > frewind (f). > > a=fread (frecament2Power1roombit8 = > int8',8) a = 6662% is preceded by bit8. For any type of bitN, when skipping means to skip several bit > > frewind (f); > > a=fread (frecoment 2Powerbit16 = > int8',8) a = 127.2% is read in two bytes (bit16), so it is 66 and 77 for the first time, and then it will be converted to int, and the range represented by int is-128q127, so it becomes 127th. And then skip 62, the next number is 2, and the next number is 0, so it adds up to 0.
In addition, the most complete form of call is
[data, n] = fread (fid, N,'a = > bouncy, nn, 'lmax ncompanyb.')
The function of the last parameter is to specify the big end and the small end. Windows uses the intel to use the small end, and the low address puts low bytes, so read 66 and 77 meme 66 in the low address, he is the low byte, 77 is the high address, is the high byte, the result is the 66'77 '256 Magi UINX and so on is generally the big end. Network communication is generally large-end.
'b': big end
'l': small end
'n': it turned out that the big end is now the big end, and the original small end is now the small end!
The n returned means that several units have actually been read. Comparing n with N, the equality means that the N pieces of data needed have been read in.
About how to carry on the MATLAB fread function analysis to share here, hope that the above content can have some help to everyone, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.