I'm confused about how to determine the delimiter between columns for data like this
14 views (last 30 days)
Show older comments
Hello, Community
I have a simple question but it was actually difficult to me. So i have data like this :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1718891/image.png)
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 :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1718896/image.png)
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 Comment
Accepted Answer
Voss
on 20 Jun 2024
Use fixedWidthImportOptions, e.g.:
opts = detectImportOptions(filename,'FileType','fixedwidth'); % modify opts as necessary T = readtable(filename,opts);
or:
T = readtable(filename,'FileType','fixedwidth');
0 Comments
More Answers (0)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!