Textscan for comma seperated file with mixed format

4 ビュー (過去 30 日間)
Thijs Van de Wiel
Thijs Van de Wiel 2021 年 1 月 20 日
コメント済み: Thijs Van de Wiel 2021 年 1 月 20 日
I am trying to use the textscan function with a text file where the delimiter is a comma(,). I load the text file using:
f=fread(fid,'*char')';
Which gives me a variable f that looks like:
f = '2020-01-20 00:00:00,1,2,4,5,Not Connected,,,NaN,10,5';
The variable f contains strings and numeric data but I only want to use the numeric data. The format can change between measurements and the data does have multiple lines which I am not able to recreate now in the example.
Using code: textscan(f,'%f',11,'delimiter',',') will not give me an output as expected. I would expect a 11 by x cell array with only floating numbers or else a NaN.
How can I get this code to work?

採用された回答

Bob Thompson
Bob Thompson 2021 年 1 月 20 日
Have you tried using readtable? It has a delimited text option, and tends to be a bit better about handling different types of data.
f = readtable(fid,'Filetype','delimitedtext','Delimiter',',');
This is untested, because I don't have access to a sample file for you, but it should be something of that form.
  1 件のコメント
Thijs Van de Wiel
Thijs Van de Wiel 2021 年 1 月 20 日
Yes I have tried that, unfortuanetly it did take quite a lot of time to compute that for a large data set. Therefore I preferred using textscan since if the data set would be all floating numbers this method is the fastest.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by