How to skip (variable) white space using textread
显示 更早的评论
If I have a text file with different amount of white spaces in between the text and numbers, how can I get "textread" to ignore the (variable) whitespaces? For example see test(002).txt
Eventually I want to make a table with these variables to make plots and do statistics etc.
采纳的回答
更多回答(1 个)
Walter Roberson
2018-3-30
I suggest using
readtable()
I do not recommend textread() in any release from R14 onwards. (I do not mean R2014* -- I mean R14, MATLAB 7.0, release in June 2004.)
7 个评论
Angelique Remmers
2018-4-4
Angelique Remmers
2018-4-4
Angelique Remmers
2018-4-4
Walter Roberson
2018-4-4
You do not readtable() a file identifier, you readtable() a file name.
T = readtable(filename);
However if you are getting a fileID of -1 then it probably cannot find the file, and you might need to specify the directory name as well. For example,
[filename, filepath] = uigetfile('*.dat', 'Choose a data file');
if ~ischar(filename)
return; %user cancel
end
filename = fullfile(filepath, filename);
T = readtable(filename);
Angelique Remmers
2018-4-5
Angelique Remmers
2018-4-5
Walter Roberson
2018-4-5
readtable() will take care of this for you.
If you use textscan() then use a format of '%s%s%s%s', and do not bother using MultipleDelimsAsOne . Any amount of whitespace on input is skipped before a %s or numeric format item is processed.
类别
在 帮助中心 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!