readtableで空白を認識させるにはどうすればよいでしょうか。
Show older comments
現在、添付ファイルのようなy座標のデータの開始行がずれてしまい空白ができた表データをそのままの形でインポートしたいと考えています。
下記のコードだと空白を認識できないのですが、どうすれば認識できるようになるでしょうか。
opts = detectImportOptions(filename);
opts.DataLines = [2 inf];
opts.VariableNames = {'Register','X','Y','NA'};
opts.VariableTypes = {'char','char','char','char'};
inputdata = readtable("test_readtable.txt",opts);
Accepted Answer
More Answers (1)
デリミタ文字が不明または不規則なテキストに対しては、デリミタ文字を認識するアプローチから読み込みたい文字列をパターンマッチングで認識するアプローチに変更する事をおすすめします。
rgx = '^\s*(\d+)\s+([0-9a-f]{16})*\s+([0-9a-f]{16})*\s+(\*{16})*';
str = fileread('test_readtable.txt');
tkn = regexp(str,rgx,'tokens','lineanchors');
tkn = vertcat(tkn{:});
cell2table(tkn,'VariableNames',{'Register','X','Y','NA'})
尚、テキストのImportOptionsにパターンマッチングがないか探しましたが見当たりませんでした。
Categories
Find more on テキスト ファイル 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!