获得一个特定的段落. txt文件

1视图(30天)
这可能听起来像一个愚蠢的问题,但是有特定段落. txt文件检索的方法吗?我写的各种实验条件一个txt文件,所以喜欢
test1
- - - - - -
- - - - - -
test2
- - - - - -
- - - - - -
等等。我在想如果我可以说得到用户输入测试数量(gui),然后使用strcat函数合并测试,然后以某种方式检索段落对应于这个数字所以我可以显示它的gui。有没有一种方法做的吗?
谢谢

接受的答案

沃尔特·罗伯森
沃尔特·罗伯森 2016年7月15日
filecontent = fileread (“YourFile.txt”);
testnum = 2;
par_begin_pos = regexp (filecontent sprintf (“^测试% d 'testnum),“lineanchors”);
如果isempty (par_begin_pos)
流(“不段# % d文件”,testnum);
返回
结束
par_end_pos = regexp (filecontent sprintf (“^测试% d 'testnum + 1),“lineanchors”);
如果isempty (par_end_pos)
par_end_pos =长度(filecontent) + 1;%对测试文件的最后一件事
结束
paragraph_content = filecontent (par_begin_pos: par_end_pos - 1);

标签

社区寻宝

找到宝藏在MATLAB中央,发现社区如何帮助你!

开始狩猎!