Xxx_rdw.textread('xxx.txt ',' % s', 'delimiter', '/N ');
Is to read the file xxx.txt in simplified format. The xxx_rd is an array of N * 1 cells. The content of each cell is a string corresponding to a line of text.
Delimiter is a delimiter. You can specify multiple delimiter. For example, you can specify '/N' and' at the same time. 'And space are separators:
Xxx_rdw.textread('xxx.txt ',' % s', 'delimiter', '/N ,');
Note: For clarity, the names of variables are usually received.CompositionIf the file name is xxx.txt, the variable name xxx_rd is received, and xxx_rd is processed in a series to get the final variable XXX.
--
The advantage of reading files in the above method is that there is no omission in the information-first read the text unharmed, and then perform various processing, and the processing should also be performed on the copy, ensure the integrity of the source.
The most common processing is to extract numeric values. For a line of text (string), values are extracted sequentially and stored in a vector, which can be implemented by the following custom functions:
Function valus = getvalu (STR) Valus = []; Valustr = []; For I = 1: length (STR) If (STR (I)> = '0' & STR (I) <= '9') | STR (I) = '.' Valustr = [valustr, STR (I)]; Else If ~ (Isempty (valustr) | (length (valustr) = 1 & valustr (1) = '.')) Valus = [valus, str2num (valustr)]; Valustr = []; End End End If ~ (Isempty (valustr) | (length (valustr) = 1 & valustr (1) = '.')) Valus = [valus, str2num (valustr)]; End End |
If you want to form a matrix of values extracted from each row, you only need to write a loop.
--
In addition, the common processing is to fill in a struct with the content of the read text (which also needs to extract numeric values). It is also done through loops and is not difficult to write.