Count number of lines between strings in a text file.

3 次查看(过去 30 天)
I have a set of text files with varying amounts of information (i.e. different numbers of lines) in the header. One example file has the following header:
######################################################################
Test File Name: 202204221121
Timestamp: 360
Test Type: EMPTY Valve Selction: BOTH Valve Cycle Time: 2 Test Duration: 360
Pressure Offsets: -0.407,-0.106,-0.190,-0.372,-0.877
Pressure Scaling Data (Upstream down):
InMin,InMax,OutMin,OutMax
16501,18733,675.320,687.525
16101,21331,656.950,686.050
19887,23890,662.13,684.61
15685,20960,656.95,686.05
15276,17316,654.97,666.25
Hawser Scaling Data (lb units)
-1 -.5 -.25 -.125 0 .125 .25 .5 1
27445,33590,36514,37849,39040,40940,42447,45795,50644
27675,33733,36900,37733,39318,40586,41633,44150,49800
29547,33785,36515,37444,41439,41863,43196,45851,52125
######################################################################
How can I programmatically determine the number of lines between the "########" lines? Thanks!

采纳的回答

Jan
Jan 2022-4-26
S = readlines(filename);
Index = find(startsWith(S, '#'));
Len = diff(Index) - 1 % Length of the blocks

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Testing Frameworks 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by