I'm confused about how to determine the delimiter between columns for data like this

6 次查看(过去 30 天)
Hello, Community
I have a simple question but it was actually difficult to me. So i have data like this :
To extract the above data column by column, I used the readtable function with the detectImportOptions like this :
cek_web_kyoto_quicklook = detectImportOptions(pathfile_web_kyoto_quicklook{bul_quicklook},'ReadVariableNames',false, 'Delimiter', " ", 'EmptyFieldRule', 'missing', 'EmptyLineRule', 'skip',...
'Whitespace', {'\b\t ',''}, 'FileType','text',...
'ConsecutiveDelimitersRule', 'join');
cek_web_kyoto_quicklook.VariableTypes = {'string', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double'};
cek_web_kyoto_quicklook.VariableNames = {'waktu', 'baseval', 'dst1', 'dst2', 'dst3', 'dst4', 'dst5', 'dst6', 'dst7', 'dst8', 'dst9', 'dst10', 'dst11', 'dst12', 'dst13', 'dst14', 'dst15', 'dst16', 'dst17', 'dst18', 'dst19', 'dst20', 'dst21', 'dst22', 'dst23', 'dst24', 'mean_dst'};
Tabel_Web_kyoto_quicklook0 = readtable(pathfile_web_kyoto_quicklook, cek_web_kyoto_quicklook);
Nan_tabeldst_quicklook = standardizeMissing(Tabel_Web_kyoto_quicklook0(:,2:end), {9999});
Tabel_Web_kyoto_quicklook0(:,2:end) = Nan_tabeldst_quicklook;
Tabel_Web_kyoto_quicklook = Tabel_Web_kyoto_quicklook0(1:end-1,:);
However, i dont know how to fix one of nargin inside of the detectImportOptions function, specifically " Delimiter ". I just set the Delimiter with ' ', and the result becomes like this :
From the above result in command window, numbers without separated by spaces (-127-120-120-128-124-112-112-112-110-120-117) will be NaN data, but numbers separated by spaces (-96 -88 -80 -76 -71 -75 -78 -73) will still be correct data.
The question is: How to make the data that is not separated by spaces (-127-120-120-128-124-112-112-110-120-117) can still be extracted/retrieved into complete data, which is as follows: -127 -120 -120 -128 -124 -112 -112 -112 -110 -120 -117
Any answer will be very helpful to me in finding this solution, for example by using other functions other than readtable or detectImportOptions
Thus submitted a question from me, thank for your attention and cooperation
  1 个评论
Stephen23
Stephen23 2024-6-20
编辑:Stephen23 2024-6-20
"I'm confused about how to determine the delimiter between columns for data like this"
Your data does not use delimiters. Your data is fixed width.
The space characters merely align the data, but do not delimit the fields.

请先登录,再进行评论。

采纳的回答

Voss
Voss 2024-6-20

Use fixedWidthImportOptions, e.g.:

opts = detectImportOptions(filename,'FileType','fixedwidth');
% modify opts as necessary 
T = readtable(filename,opts);

or:

T = readtable(filename,'FileType','fixedwidth');

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by