matlab 数据读取

load()只能读入每一行列数相等的数据

可以使用textread函数

具体用法在下面的链接

http://blog.sina.com.cn/s/blog_9e67285801010bju.html

我的数据可以通过跳行的方法

textread

基本语法是:

    [A,B,C,…] = textread(filename,format)

    [A,B,C,…] = textread(filename,format,N)


跳行

myfiles.txt 中的内容如下:

    % this a comment

    1, 2, 3, 4

    5, 6, 7, 8

    9, 10, 11, 12

>> [data1,data2,data3,data4]=textread('myfiles.txt','%n%n%n%n','delimiter', ',','headerlines', 1);
>>  data=[data1 data2 data3 data4]

data =

     1     2     3     4
     5     6     7     8
     9    10    11    12
textread中的headerlines指明了跳过几行,1可自由设定
这里headerlines告诉textread跳过一开始的1行,1可以替换为任意你要跳过的行数。



也可以通过屏蔽字符的方式

屏蔽字符

   例4.1: 如果要忽略12.34这个浮点数。

    [names, types, y, answer] = textread('myfileli4.txt' , '%s %s %*f %d %s', 1)

    %*f 告诉textread跳过一个浮点数。
names =

    'Sally'


types =

    'Level1'


y =

    45


answer =

    'Yes'

对于iris.txt如果只想读取数据可用[data1,data2,data3,data4]=textread('Iris.txt','%f %f %f %f %*s',150,'delimiter',',');
____________________________________________________________________________________________

 例:4.2  如果要忽略Level,指读取后面的数字,

 >> [names, levelnum, x, y, answer] = textread('myfileli4.txt','%s Level%d %f %d %s', 1)

names =

    'Sally'


levelnum =

     1


x =

   12.3400


y =

    45


answer =

    'Yes'


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值