matlab 读文件csvread textread用法实例
2014-03-17 22:31
681 查看
例1
建立文件csvlist.dat
里面数据是
02, 04, 06, 08, 10, 12
03, 06, 09, 12, 15, 18
05, 10, 15, 20, 25, 30
07, 14, 21, 28, 35, 42
11, 22, 33, 44, 55, 66
然后将文件保存到work里,本版是保存到bin里,
在matlab里执行,
>> csvread('csvlist.dat')
运行结果:
ans =
2 4 6 8 10 12
3 6 9 12 15 18
5 10 15 20 25 30
7 14 21 28 35 42
11 22 33 44 55 66
输入
m = csvread('csvlist.dat', 2, 0)
输出
m =
5 10 15 20 25 30
7 14 21 28 35 42
11 22 33 44 55 66
m = csvread('csvlist.dat', 2, 0, [2,0,3,3])
m =
5 10 15 20
7 14 21 28
例2 textread的用法
mydata.dat 内容第一行
Sally Level1 12.34 45 Yes
输入
[names, types, x, y, answer] = textread('mydata.dat', ...
'%s %s %f %d %s', 1)
returns
names =
'Sally'
types =
'Level1'
x =
12.34000000000000
y =
45
answer =
'Yes'
输入[names, types, y, answer] = textread('mydata.dat', ...
'%9c %6s %*f %2d %3s', 1)
忽略含小数点的数
returns
names =
Sally
types =
'Level1'
y =
45
answer =
'Yes'
第一行是Sally Type1 12.34 45 Yes
输入
[names, typenum, x, y, answer] = textread('mydata.dat', ...
'%s Type%d %f %d %s', 1)
忽略掉字母Type
returns
names =
'Sally'
typenum =
1
x =
12.34000000000000
y =
45
answer =
'Yes'
文件中内容是
1,2,3,4,,6
7,8,9,,11,12
输入
data = textread('data.csv', '', 'delimiter', ',', ...
'emptyvalue', NaN);
用NaN填充’’空值
例1
建立文件csvlist.dat
里面数据是
02, 04, 06, 08, 10, 12
03, 06, 09, 12, 15, 18
05, 10, 15, 20, 25, 30
07, 14, 21, 28, 35, 42
11, 22, 33, 44, 55, 66
然后将文件保存到work里,本版是保存到bin里,
在matlab里执行,
>> csvread('csvlist.dat')
运行结果:
ans =
2 4 6 8 10 12
3 6 9 12 15 18
5 10 15 20 25 30
7 14 21 28 35 42
11 22 33 44 55 66
输入
m = csvread('csvlist.dat', 2, 0)
输出
m =
5 10 15 20 25 30
7 14 21 28 35 42
11 22 33 44 55 66
m = csvread('csvlist.dat', 2, 0, [2,0,3,3])
m =
5 10 15 20
7 14 21 28
例2 textread的用法
mydata.dat 内容第一行
Sally Level1 12.34 45 Yes
输入
[names, types, x, y, answer] = textread('mydata.dat', ...
'%s %s %f %d %s', 1)
returns
names =
'Sally'
types =
'Level1'
x =
12.34000000000000
y =
45
answer =
'Yes'
输入[names, types, y, answer] = textread('mydata.dat', ...
'%9c %6s %*f %2d %3s', 1)
忽略含小数点的数
returns
names =
Sally
types =
'Level1'
y =
45
answer =
'Yes'
第一行是Sally Type1 12.34 45 Yes
输入
[names, typenum, x, y, answer] = textread('mydata.dat', ...
'%s Type%d %f %d %s', 1)
忽略掉字母Type
returns
names =
'Sally'
typenum =
1
x =
12.34000000000000
y =
45
answer =
'Yes'
文件中内容是
1,2,3,4,,6
7,8,9,,11,12
输入
data = textread('data.csv', '', 'delimiter', ',', ...
'emptyvalue', NaN);
用NaN填充’’空值
相关文章推荐
- MATLAB中IF 条件语句 用法以及实例
- Linux中使用SecureCRT上传、下载文件命令sz与rz用法实例
- MATLAB save 函数用法及实例
- Matlab 之meshgrid, interp, griddata 用法和实例
- XSD(XML Schema Definition)用法实例介绍以及C#使用xsd文件验证XML格式
- JSP页面文件中base标记用法实例分析
- 文件 I/O——实例1:open函数close函数lseek函数用法
- Matlab 之meshgrid, interp, griddata 用法和实例
- XSD(XML Schema Definition)用法实例介绍以及C#使用xsd文件验证XML格式
- 实例讲解ThinkPHP的UploadFile文件上传类的详细用法
- MATLAB关于文件操作的一些基本用法
- php文件缓存类用法实例分析
- Matlab中读取文件中数据的函数用法
- Linux中使用SecureCRT上传、下载文件命令sz与rz用法实例
- VC调用matlab中定义的.m文件中的函数的实例
- Linux中使用SecureCRT上传、下载文件命令sz与rz用法实例
- python开发之文件操作用法实例
- plupload文件上传事件用法实例
- 【matlab】eps 意义用法以及实例
- php文件压缩之PHPZip类用法实例