如何在 MATLAB(2016 及更高版本)中读取文本文件时省略部分行
How to omit parts of a line while reading a text file in MATLAB (2016 and above)
我需要开发一个 MATLAB 代码来读取文本文件。
这些行具有以下形式:
| 1 | 1 | 6.000 | 454.000 | 423 |
| 1 | 1 | 11.000 | -454.000 | 426 |
| 1 | 1 | 45.000 | 454.000 | 428 |
有没有办法省略竖线(只保留数字?)
非常感谢!
MATLAB 提供 multiple different file IO options
例如,您可以使用 textscan
:
fID = fopen('test.txt');
test = textscan(fID, '%*u %u %u %f %f %u', 'Delimiter', '|');
fclose(fID);
您可以 manipulate/concatenate 根据需要 returns n x 5
cell array 列。
或者您可以使用 readtable
:
mydata = readtable('test.txt', 'Delimiter', '|', 'Format', '%*u %u %u %f %f %u');
returns n x 5
table
你的数据。
我需要开发一个 MATLAB 代码来读取文本文件。 这些行具有以下形式:
| 1 | 1 | 6.000 | 454.000 | 423 |
| 1 | 1 | 11.000 | -454.000 | 426 |
| 1 | 1 | 45.000 | 454.000 | 428 |
有没有办法省略竖线(只保留数字?)
非常感谢!
MATLAB 提供 multiple different file IO options
例如,您可以使用 textscan
:
fID = fopen('test.txt');
test = textscan(fID, '%*u %u %u %f %f %u', 'Delimiter', '|');
fclose(fID);
您可以 manipulate/concatenate 根据需要 returns n x 5
cell array 列。
或者您可以使用 readtable
:
mydata = readtable('test.txt', 'Delimiter', '|', 'Format', '%*u %u %u %f %f %u');
returns n x 5
table
你的数据。