필터 지우기
필터 지우기

Cannot import csv data with textscan

조회 수: 2 (최근 30일)
Thomas Hermelin
Thomas Hermelin 2017년 10월 25일
편집: Thomas Hermelin 2017년 10월 25일
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??

답변 (1개)

KSSV
KSSV 2017년 10월 25일
use xlsread
[num,txt,raw] = xlsread('test.csv') ;
  댓글 수: 1
Thomas Hermelin
Thomas Hermelin 2017년 10월 25일
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 !

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by