How do I read begin to read data after a string?
4 次查看(过去 30 天)
显示 更早的评论
In a txt file, I want to collect fcz data after "Concrete Stresses", how do I also Import the txt file to do so appropriately.
CONCRETE STRESSES
*****************
ELMT fcx fcy fcz Vcxy Vcyz Vcxz
(MPa) (MPa) (MPa) (MPa) (MPa) (MPa)
1 0.000 0.000 0.000 0.000 0.000 0.000
2 0.000 0.000 0.000 0.000 0.000 0.000
3 0.000 0.000 0.000 0.000 0.000 0.000
4 0.000 0.000 0.000 0.000 0.000 0.000
5 0.000 0.000 0.000 0.000 0.000 0.000
0 个评论
采纳的回答
Walter Roberson
2020-8-5
filename = 'ConcreteStresses.txt';
S = fileread(filename);
idx = regexp(S, '^\s*\d', 'once', 'lineanchors');
fmt = repmat('%f', 1, 7);
data = cell2mat( textscan(S(idx:end), fmt) );
fcz = data(:,4);
1 个评论
Walter Roberson
2020-8-5
In the case where the position of the first line of numeric data is known, it is even easier:
filename = 'ConcreteStresses.txt';
fid = fopen(filename);
fmt = repmat('%f', 1, 7);
data = cell2mat( textscan(fid, fmt, 'headerlines', 6));
fclose(fid);
fcz = data(:,4);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!