从 Matlab 读取文本文件时查找特定字符串所在的行
我有一个文本文件,其中包含字符串周围的连续整数值。该文件看起来像这样:
This is the set for x = 100
---------------------------
For y=COLUMN 1 we have
1232
3ff3
4a45
23d4
5323
...
...
END of COLUMN 1 meas
For y=COLUMN 2 we have
1232
3c43
4545
2d24
5a23
...
...
END of COLUMN 2 meas
This is the set for x = 200
---------------------------
For y=COLUMN 1 we have
2b23
1232
d387
6f74
4c47
...
...
END of COLUMN 1 meas
For y=COLUMN 2 we have
354d
a546
3c63
5a46
a349
...
...
END of COLUMN 2 meas
This is the set for x = 530
---------------------------
..........
..........
我想做的是将字符串之间的值存储到单独的数组中。也就是说,从“For y=COLUMN 1 we have”到“END of COLUMN 1 meas”将存储到ArrayA中,从“For y=COLUMN 2 we have”到“END of COLUMN 2 meas”存储到ArrayB中,等等 之后,
我需要找到“x”的所有值并将它们存储到名为 ArrayX 的字符串数组中。也就是说,它应该是这样的:
ArrayX =
'x=100' 'x=200' 'x=501'
如果有人可以提供帮助,我将非常感激。
I have a text file that has consequtive integer values around strings. This file looks like that:
This is the set for x = 100
---------------------------
For y=COLUMN 1 we have
1232
3ff3
4a45
23d4
5323
...
...
END of COLUMN 1 meas
For y=COLUMN 2 we have
1232
3c43
4545
2d24
5a23
...
...
END of COLUMN 2 meas
This is the set for x = 200
---------------------------
For y=COLUMN 1 we have
2b23
1232
d387
6f74
4c47
...
...
END of COLUMN 1 meas
For y=COLUMN 2 we have
354d
a546
3c63
5a46
a349
...
...
END of COLUMN 2 meas
This is the set for x = 530
---------------------------
..........
..........
What I would like to do is to strore the values in between the strings into seperate arrays. That is, from 'For y=COLUMN 1 we have' to 'END of COLUMN 1 meas' will be strored in to ArrayA, from 'For y=COLUMN 2 we have' to 'END of COLUMN 2 meas' into ArrayB, etc.
After that, I need to find all the values fo 'x' and store them into a string array named ArrayX. That is, this should be look like that:
ArrayX =
'x=100' 'x=200' 'x=501'
If anyone can help, I will really appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您是否仍然需要此信息,但我有同样的问题并找到了此解决方案;
现在我有一个包含所有需要的符号的大矩阵。我获取了你的数据并得到了这个:
所以最后一步是将这个矩阵划分为几个。例如,对于您的
ArrayX
:我找不到一些优雅的方法来按照您想要的列数划分
A
,并且只是使用循环以相同的方式完成。I'm not sure you still need this information, but I have the same problem and find this solution for this;
Now I have big matrix with all needed symbols. I took your data and get this:
So the last step is to divide this matrix at several. For example for your
ArrayX
:I can't find some elegant way to divide
A
at number of columns as you wanted and just done the same way using loop.