UIIMPORT 是一个功能强大,易于使用的基于 GUI 的 high level routine,用
于读 complex data files。文件也必须是 homogeneous。
IMPORTDATA 形成 UIIMPORT 的功能,不打开 GUI。可以将 IMPORTDATA
用于函数或者脚本中,因为在函数或者脚本中基于 GUI 的文件导入机制并不理
想。下面的例子用到包含几行文件头和文本、数值数据的文件
'sample_file2.txt':
This is a file header.
This is file is an example.
col1 col2 col3 col4
A 1 4 612.000
B 1 4 613.000
C 1 4 614.000
D 1 4 615.000
Example: Using IMPORTDATA to read in a file with headers, text, and
numeric data
CODE:
% This reads in the file 'sample_file2.txt' and creates a
% structure D that contains both data and text data.
% Note the IMPORTDATA command specifies a white space
% as the delimiter of the file, but IMPORTDATA can usually
% detect this on its own
D = importdata('sample_file2.txt','') % 原文有误?
D = importdata('sample_file2.txt')
可以通过访问结构 D 的数据和文本域,来看结构 D 中的真实值,例如输入:
data = D.data
text = D.textdata
可以用 UIIMPORT 读同一个文件并得到同样的结构.