![](https://csdnimg.cn/release/download_crawler_static/87517849/bg4.jpg)
注意: 对于 ASCII data, 你必须检验导入向导正确的识别了列分隔符。
TEXTREAD/STRREAD
TEXTREAD 是一个强大的动态 high level routine,设计用来读 ASCII 格式的
文本和/或数值数据文件。STRREAD 除是从字符串而不是文件读以外,类似于
TEXTREAD。
两个函数可以用许多参数来改变其具体的工作方式,他们返回读入指定输出的数
据。他们有效的提供给你一个
“两全其美”的方法,因为他们可以用一个命令读入混合的 ASCII 和数值数据
(high level routines的做法),并且你可以改变他们以匹配你特定的应用(如
同 low level routines 做到的)。例子:
CODE:
Example 1: Using TEXTREAD to read in an entire file into a cell array
% This command reads in the file fft.m into the cell array, file
file = textread('fft.m','%s','delimiter','\n','whitespace','');
CODE:
Example 2: Using STRREAD to read the words in a line
% This command uses the cell array created in Example 1 to
% read in each word of line 28 in 'file' to a cell array, words
words = strread(file{28},'%s','delimiter','')
CODE:
Example 3: Using TEXTREAD to read in text and numeric data from a
file with headers
% This command skips the 2 header lines at the top of the file
% and reads in each column to the 4 specified outputs
[c1 c2 c3 c4] =
textread('sample_file2.txt','%s %s %s %s','headerlines',2)