从ASCII文件中将文本值读入matlab变量 [英] Reading text values into matlab variables from ASCII files
问题描述
var1 var2 variable3
1 2 3
11 22 33
我想将数字加载到矩阵中,并将列标题加载到等同于:
variable_names = char('var1','var2','variable3');
我不介意在两个文件中分割名字和数字,但是准备matlab代码文件并评估他们不是一个选项。
请注意可以有任意数量的变量(列)
我为这样的操作建议 importdata :
d = importdata('filename.txt );
返回值是一个结构,其中的数字字段位于名为data的成员中,列标题在一个名为colheaders的字段中。
导入操作数据的另一个有用界面是Statistics Toolbox中的'dataset'类。
Consider the following file
var1 var2 variable3
1 2 3
11 22 33
I would like to load the numbers into a matrix, and the column titles into a variable that would be equivalent to:
variable_names = char('var1', 'var2', 'variable3');
I don't mind to split the names and the numbers in two files, however preparing matlab code files and eval'ing them is not an option.
Note that there can be an arbitrary number of variables (columns)
I suggest importdata for operations like this:
d = importdata('filename.txt');
The return is a struct with the numerical fields in a member called 'data', and the column headers in a field called 'colheaders'.
Another useful interface for importing manipulating data like these is the 'dataset' class available in the Statistics Toolbox.
这篇关于从ASCII文件中将文本值读入matlab变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!