Matlab中读取文件中数据的函数用法
1、load()函数
文件sample_file.txt中的数据:
在MATLAB命令行中运行结果:
>> M=load("sample_file.txt")
M =
1 5 4 16 8
5 43 2 6 8
6 8 4 32 1
90 7 8 7 6
5 9 81 2 3
2、importdata()函数
>> data=importdata("sample_flie_plus5.mat")data =
6 10 9 21 13
10 48 7 11 13
11 13 9 37 6
95 12 13 12 11
10 14 86 7 8
>> D = importdata("sample_file2.txt")
D =
data: [4x3 double]
textdata: {7x4 cell}
>> data=D.data
data =
1 4 612
1 4 613
1 4 614
1 4 615
>> text=D.textdata
text =
"This is a file h..." [] [] []
"This is file is ..." [] [] []
"col1" "col2" "col3" "col4"
"A" "" "" ""
"B" "" "" ""
"C" "" "" ""
"D" "" "" ""
3、textread()函数
"sample_file2.txt"文件:
此处headerlines 及3的含义是:从文件读取内容时忽略掉前3行
>> [c2 c3 c4]=textread("sample_file2.txt","%*s %d %d %f","headerlines",3)
c2 =
1
1
1
1
c3 =
4
4
4
4
c4 =
612
613
614
615
- 上一篇: Matlab实现文件读写的几种方法(确实很好,不错)
- 下一篇:没有了