Problem when importing a TXT file into MATLAB with "readtable". Text and numbers are between single quotes...

16 ビュー (過去 30 日間)
Hello everyone,
I am facing a big issue when trying to read a table from a TXT file. The data appears to be normal in Excel and in Wordpad but not in Matlab. Why does not Matlab recognize numerical data and import it as so?
So far I have the following sequence:
data=readtable('example.txt);
And then I get the following (see picture).
How can I get rid of the single quotes and treat the numerical data (from column 3 on) normally?
I would really appreciate your help in this regard.
Best,
Joseba

採用された回答

madhan ravi
madhan ravi 2019 年 2 月 13 日
編集済み: madhan ravi 2019 年 2 月 13 日
T=table2cell(data);
T(:,3:end)=cellfun(@str2double,T(:,3:end),'un',0)
  2 件のコメント
Joseba Moreno
Joseba Moreno 2019 年 2 月 14 日
Dear Madhan ravi,
Thank you really much for your answer, it worked perfectly!
Now I would also like to convert the first two columns "Datum" and "Zeit" to a format I can use for plotting these against the numerical data (from column 3 on). How can I do that?
Thank you very much again.
Best,
Joseba
madhan ravi
madhan ravi 2019 年 2 月 14 日
It would be better if you ask a separate question by providing all the necessary details, as I have answered your original question.

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

その他の回答 (1 件)

Peter Perkins
Peter Perkins 2019 年 2 月 17 日
The real problem is that there's something funny in your file that you are not telling us about. Part of it may be using comma as the decimal separator (which I think can be addresses using detectimportoptions, part of which is the specific date format, which again can be addressed with detectimportoptions.
But I'm guessing that the main issue is that all the numeric values in your file are quoted.
Normally, readtable in a recent version of MATLAB should read data like what you have with little or no guidance, and you certainly should not have to call str2double all over the place. A SMALL snippet of you file would help others in diagnosing your problem.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by