matlab - 如何删除matlab中文本文件中的前导空格?

标签 matlab

我有一个文本文件 (*.txt),其中某些行以空格开头,我想删除所有前导空格。 文本有将近 20k 行,其中某些随机行在开头有一个空格。因此,我很难阅读这些行。 我想删除前导空格,以便可以正确阅读。

最佳答案

尝试使用以下代码:

inputFileID=fopen('input.txt','r'); % Open input file for reading
outputFileID=fopen('output.txt','w'); % Open output file for writing

formatted_lines_in_cell_array = textscan(inputFileID,'%s','Delimiter','\n'); % Scan input file, and split to rows
formatted_lines=formatted_lines_in_cell_array {1,1}; % Extract the formatted lines array from the 1x1 cell array output of textscan

fprintf(outputFileID,'%s\r\n',formmated_lines{:}); % Write formatted lines to output file

fclose(inputFileID); % Close files
fclose(outputFileID);

关于matlab - 如何删除matlab中文本文件中的前导空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49974388/

相关文章:

matlab - 使用 MatLab 按不同强度分割对象

matlab - 在 Matlab 中检查像素

MATLAB 中的 C++ MEX 编译

arrays - 将 NX1 矩阵的一个元素与另一个元素相减

Matlab图像显示在特定的老数字

matlab - 如何使用 matlab 正确绘制矢量线性方程?

matlab - 在MATLAB中从结构中删除字段

java - 庞加莱指数法(指纹奇异点)

performance - 将参数传递给 cellfun matlab

matlab - 是否可以在 WindowButtonMotionFcn 中使用多个回调?