How do I read begin to read data after a string?

조회 수: 26 (최근 30일)
Desmond Hutchinson
Desmond Hutchinson 2020년 8월 5일
댓글: Walter Roberson 2020년 8월 5일
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

채택된 답변

Walter Roberson
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
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 CenterFile Exchange에서 Biological Physics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by