xiaoerh 发表于 2012-4-6 10:56:38

求助,如何读取文本数据

文本文档内容如下,求教如何在matlab中读取‘Real mass =’,‘Real max_bar_stress = ’,‘Real max_vonmises =’,‘Real frequency = ’后的数值
!
! VARIABLES
!
String section_number = "6" !
Integer thickness = 9 !
!
! OUTPUTS
!
Real mass = 4995588.0 ---> Mass !
Real max_bar_stress = 1.189315E+2 ---> At Element 737 !
Real max_vonmises = 3.993584E+1 ---> At Element 321 !
Real frequency = 0.02003384 ---> Frequency !

qibbxxt 发表于 2012-4-6 13:51:18

1. textscan
2. regexp
3. 低级格式去读
帮助文件里面都有介绍

blackbutter 发表于 2012-4-10 08:46:31

fid=fopen('----------.txt');
data=fscanf(fid,'%s');
index1 = findstr(data_iq,'Real mass =');
index2 = findstr(data_iq,'Real max_bar_stress =');
index3 = findstr(data_iq,'Real max_vonmises =');
index4 = findstr(data_iq,'Real frequency =');
%%%%%%%%%%%%%找到数据位置后就可以读取了%%

data1=data(index1+1);
......

狼跃冲顶 发表于 2012-4-12 13:41:07

qibbxxt 发表于 2012-4-6 13:51 static/image/common/back.gif
1. textscan
2. regexp
3. 低级格式去读


regexp是否是正则表达式
而textscan是一部字符串处理呢?

wyzheng352 发表于 2012-4-14 21:09:56

干嘛那么麻烦啊
直接用load
A=load( filename);
X=A(2:,1);
y=A(2:,2);
页: [1]
查看完整版本: 求助,如何读取文本数据