Filter löschen
Filter löschen

Cannot import csv data with textscan

1 Ansicht (letzte 30 Tage)
Thomas Hermelin
Thomas Hermelin am 25 Okt. 2017
Bearbeitet: Thomas Hermelin am 25 Okt. 2017
Hi, I'm trying to import several csv files to use the data. The problem is that xlsread is too slow and csvread, dlmread or importdata don't work. I suspect the encoding to be the source of the problem. So I'm trying to use textscan to do it.
My csv file is looking like that:
N°. x[mm] y[mm] Rotation / x[°]
1 30.92221 3.66636
2 30.92751 3.66634 -0.259299
3 30.93981 3.66649 0.696742
4 30.94510 3.66680 3.36023
5 30.95740 3.66706 1.24399
6 30.96970 3.66663 -2.04397
7 30.97500 3.66638 -2.66614
8 30.98029 3.66614 -2.61545
9 30.99259 3.66589 -1.17048
10 30.99789 3.66629 4.33688
1 31.10346 3.66539 -1.00677
2 30.99259 3.66589 -1.17048
So here i'm using the following code which I think is ok :
file = fopen('test.csv','rt');
data2 = textscan(file,'%f%f%f%f','Delimiter','\t','HeaderLines',1,'TreatAsEmpty',{'N°.','x[mm]','y[mm]','Rotation / x[°]'});
But it's returning
data2 =
[0x1 double] [0x1 double] [0x1 double] [0x1 double]
When I suppress the first line, it works. It appears that the parameter 'headerlines' doesn't work...
Any idea ?
Thank you !!
PS: I work with matlab R2009a
EDIT: The ° symbol appears to be the problem, does anyone know how to suppress it directly from matlab... ? Or any solution to bypass that??

Antworten (1)

KSSV
KSSV am 25 Okt. 2017
use xlsread
[num,txt,raw] = xlsread('test.csv') ;
  1 Kommentar
Thomas Hermelin
Thomas Hermelin am 25 Okt. 2017
Yes, I forgot to mention it, I'm already using it, but it takes 8 secs to import the data vs 0.1 with textscan. That's why I'm trying to use it. Thanks for your answer !

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by