当你在Matlab中扫描文本文件时,有没有办法识别空行?我想根据文本之间的空行解析文件。这可能吗?有没有办法在Matlab中识别空行?
5
A
回答
2
是的,这是可能的。一个MATLAB代码片段看起来是这样的:
fid = fopen('reader.m');
newline = sprintf('\r\n');
line = fgets(fid);
while ischar(line)
if strcmp(newline, line)
disp('Empty line');
else
disp('Non-empty line');
end
line = fgets(fid);
end
2
这里有一个可能性:
fid = fopen('myfile.txt');
lines = textscan(fid, '%s', 'Delimiter', '\n');
fclose(fid);
lines = lines{1};
% lines now contains a cell array of strings,
% one per line in the file.
% Find all the blank lines using cellfun:
blank_lines = find(cellfun('isempty', lines));
+0
它也适用于注释:'lines = textscan(fid,'%s','CommentStyle','#')' – Wok 2012-09-13 11:46:34
0
没有\ r ...现在工作得很好
fid = fopen('reader.m');
newline = sprintf('\n');
line = fgets(fid);
while ischar(line)
if strcmp(newline, line)
disp('Empty line');
else
disp('Non-empty line');
end
line = fgets(fid);
end
相关问题
- 1. 有没有办法在Python中识别继承的方法?
- 2. 有没有办法在matlab R2011b中做命令别名?
- 3. 有没有办法让ngModel识别属性绑定语法?
- 4. 有没有办法标记或识别特定订单?
- 5. 有没有办法让TFS代码搜索识别“@”符号?
- 6. 有没有办法让rxvt识别shift + tab?
- 7. 有没有办法让Aptana识别<main>?
- 8. 有没有办法在MATLAB中编辑框中的文本?
- 9. 有没有办法让vim识别文件名末尾的行号?
- 10. 有没有办法压制背景语音识别功能并顺利运行?
- 11. #import'ing msado15.dll,有没有别的办法?
- 12. 有没有办法在MATLAB中加速这段代码?
- 13. 有没有办法在Matlab中评估Jacobian?
- 14. 有没有办法放弃空捕获?
- 15. 有没有办法检查空目录?
- 16. 有没有办法在express-resource中使用通用标识符?
- 17. 有没有办法获得在Matlab中运行的本地函数的名称?
- 18. 有没有办法使用tesseract识别图形或图片中的文字?
- 19. WebElement没有识别
- 20. 有没有办法在NetBeans
- 21. 有没有办法在Notepad ++
- 22. 有没有办法在UIWebview
- 23. 有没有办法在YAML中别名/锚定数组?
- 24. 有没有办法在NSArray的类别中使用ObjectType?
- 25. 有没有办法在Cygwin中为shebang别名?
- 26. 有没有办法从别处的目录运行SL4A脚本?
- 27. 有没有办法在GNU OpenMP中结束空闲线程?
- 28. 有没有办法在VB中转义根名称空间?
- 29. 有没有办法在SQL Server Management Studio 2016中查看空白?
- 30. 有没有办法在wpf的lineseries图表中有空值的空值?
我想,他说: “Matlab的” .. – 2010-06-16 22:17:15