coolxh 发表于 2006-3-10 20:23

在Matlab中读入数字与字符混排的文本数据

由于普通的数字与字符混排的方式复杂,并且涉及数据的分组等问题,http://forum.vibunion.com/thread-2029-1-1.html([转帖]matlab中常见txt文件读入的实用方法)中提到的方法2并不能解决上述问题
本人在处理过程中应用textread函数将各行文本(无论数字还是字符)转化为结构数组,然后再将结构数据强制转化为字符数据,最后再根据对数据文件的特征,对数据分组,该方法不涉及循环,处理速度可能比http://forum.vibunion.com/thread-2029-1-1.html([转帖]matlab中常见txt文件读入的实用方法)中提到的方法2稍慢(本从未比较二者的处理速度),但处理速度仍较快,对于文件大小为2M左右的文本文件,自读入到结果存盘不超过1分钟.
=textread(,'%s %s %s %s %s %s'); %Read the data with blank seperator
strDisp=char(TDisp);strLoad=char(TLoad);strTime=char(TTime);
strSegm=char(TSegm);strTemp=char(TTemp);%将结构数组转换为字符串数组
%
clear TLoad TTime TDisp TTemp TSegm TOrth
%
findIndex=find(strDisp(:,1)=='-');%寻找字符串数组中以'-'号开头的元素
getDisp=str2num(strDisp(findIndex,:));getLoad=str2num(strLoad(findIndex,:));
getTime=str2num(strTime(findIndex,:));getSegm=str2num(strSegm(findIndex,:));
getTemp=str2num(strTemp(findIndex,:)); %将相应元素转换为数值型数组
%
clear strDisp strLoad strTime strSegm strTemp findIndex
%=================================================================
%==
%将数据进行区分
findIndexPV=find(getLoad<0); %寻找Peak-Valley数据
findIndexCYC=find(getLoad>0);%寻找疲劳循环滞回圈的数据
文本文件为MTS生成的疲劳试验测试数据,其格式如下:
TWSX|.|/|:|1|0|0|E|2|A
Test Control Started Time: 0.01142585
Calendar Time: 11/9/04 9:23:55 AM
File Name: C:\TS2\twsx\chenxh\BeamFatigue.000
Procedure Name: SanqiaoBeamFatigue Default Procedure
Operator: MTS
Teststar Config: C:\TS2\config\3 Point Bend.tcc

DRP Process Data data aquisition Time: 2.6431799
Load Time Displacement Temperature Axial Segments Temperature Segments
N Sec mm deg_C segments segments
-1105.1283 1.9528682 -0.21360928 -74.992905 31 0
-8317.8506 1.9999999 -0.42025727 -74.999794 32 0
-1105.1283 2.0528443 -0.20327689 -74.992905 33 0
-8314.4063 2.0999761 -0.42714554 -74.992905 34 0
-1101.6838 2.1528206 -0.21016514 -74.999794 35 0

DRP Process Data data aquisition Time: 3.5334442
Load Time Displacement Temperature Axial Segments Temperature Segments
N Sec mm deg_C segments segments
-1112.0173 2.7526777 -0.22049753 -74.992905 47 0
-8310.9629 2.8009996 -0.44436622 -74.999794 48 0
-1108.5728 2.8545582 -0.21360928 -74.992905 49 0
-8314.4063 2.9004996 -0.44436622 -74.992905 50 0
-1115.4618 2.95263 -0.2273858 -74.992905 51 0

DRP Process Data start data Time: 3.8452747
Load Time Displacement Temperature Axial Segments Temperature Segments
N Sec mm deg_C segments segments
-988.0163 0.55343962 -0.10339701 -74.992905 3 0
-8200.7393 0.60057127 -0.33070982 -74.992905 4 0
-1043.1278 0.6534158 -0.13095008 -74.992905 5 0
-8255.8506 0.70078546 -0.35481876 -74.992905 6 0
-1067.2393 0.75339198 -0.13783835 -74.992905 7 0
-8262.7393 0.8007617 -0.37203944 -74.999794 8 0
-1074.1282 0.85336816 -0.15161487 -74.992905 9 0
-8276.5176 0.90073788 -0.37892771 -74.992905 10 0
-1077.5726 0.95358241 -0.16194728 -74.999794 11 0
-8286.8506 1.0007141 -0.38581592 -74.992905 12 0
-1084.4614 1.0530825 -0.16539142 -74.992905 13 0
-8283.4063 1.1002141 -0.38926005 -74.992905 14 0
-1091.3506 1.1537728 -0.17572381 -74.999794 15 0
-8293.7402 1.2016186 -0.39959246 -74.999794 16 0
-1084.4614 1.2530349 -0.18605621 -74.992905 17 0
-8297.1836 1.3008807 -0.40648073 -74.992905 18 0
-1094.795 1.3532491 -0.18261208 -74.992905 19 0
-8304.0732 1.4008569 -0.40992486 -74.999794 20 0
-1101.6838 1.4525112 -0.18950035 -74.992905 21 0
-8304.0732 1.5003569 -0.40648073 -74.992905 22 0
-1101.6838 1.5532016 -0.18950035 -74.992905 23 0
-8307.5176 1.6010473 -0.413369 -74.986023 24 0
-1094.795 1.6538918 -0.19638862 -74.992905 25 0
-8304.0732 1.7000713 -0.41681314 -74.992905 26 0
-1101.6838 1.7526778 -0.19638862 -74.999794 27 0
-8307.5176 1.7998095 -0.42370141 -74.999794 28 0
-1098.2394 1.852654 -0.20327689 -74.992905 29 0
-8310.9629 1.9000237 -0.42714554 -74.999794 30 0
-1105.1283 1.9528682 -0.21360928 -74.992905 31 0
-8317.8506 1.9999999 -0.42025727 -74.999794 32 0
-1105.1283 2.0528443 -0.20327689 -74.992905 33 0
-8314.4063 2.0999761 -0.42714554 -74.992905 34 0
-1101.6838 2.1528206 -0.21016514 -74.999794 35 0
-8310.9629 2.1999521 -0.43058968 -74.986023 36 0
-1105.1283 2.2527969 -0.22049753 -74.986023 37 0
-8310.9629 2.3001664 -0.42714554 -74.992905 38 0
-1108.5728 2.3530109 -0.21360928 -74.986023 39 0
-8310.9629 2.4001427 -0.43403381 -74.992905 40 0
-1108.5728 2.4527493 -0.21705341 -74.999794 41 0
-8314.4063 2.5003569 -0.43403381 -74.986023 42 0
-1112.0173 2.5543916 -0.21360928 -74.992905 43 0
-8317.8506 2.600333 -0.43747795 -74.986023 44 0
-1112.0173 2.6527016 -0.22049753 -74.986023 45 0
-8317.8506 2.7003093 -0.44436622 -74.986023 46 0
-1112.0173 2.7526777 -0.22049753 -74.992905 47 0
-8310.9629 2.8009996 -0.44436622 -74.999794 48 0
-1108.5728 2.8545582 -0.21360928 -74.992905 49 0
-8314.4063 2.9004996 -0.44436622 -74.992905 50 0
-1115.4618 2.95263 -0.2273858 -74.992905 51 0
-8310.9629 3.000952 -0.44092208 -74.999794 52 0
......

[ 本帖最后由 sogooda 于 2008-10-15 10:07 编辑 ]

klz225008 发表于 2008-10-15 00:38

好帖 感谢中,学到了很多东西

dragonclouder 发表于 2009-2-26 21:05

这个文件如果直接导入origin中,表头可以设置为忽略,然后导出为txt文件,那就全是数据了。楼主的做法是不是太麻烦了呢。

20051324 发表于 2009-4-29 09:44

我的文本文件超大

我的文本文件有150MB,数据将近400万个,只有两列,怎么处理好呢?用matlab有什么方法可以进行计算么?
t时间      v电压
0             xx
1             xx
。      。
。      。

下面还有超多数据

ChaChing 发表于 2009-4-29 11:38

回复 地板 20051324 的帖子

试试load或importdata

charminggu 发表于 2010-4-21 14:35

回复 楼主 coolxh 的帖子

请问Axial Segments具体是什么意思呀?
应该怎么翻译,谢谢

ChaChing 发表于 2010-4-21 15:32

回复 6楼 charminggu 的帖子

这个好像与matlab无关! :loveliness:
轴向部分??
页: [1]
查看完整版本: 在Matlab中读入数字与字符混排的文本数据