필터 지우기
필터 지우기

How Parse / import CSV file with mixed data types

조회 수: 1 (최근 30일)
Sayanta
Sayanta 2012년 5월 22일
Dear Experts,
Here is the data I want to parse / import with mat lab code. I try to use M = csvread(filename); it doesn't work. Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:46;77
Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:47;66.9016
Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:47;67.0833
Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:47;66.1
Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:48;66.3115
Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:49;66.3934
Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:49;86.8525
Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:49;78.7288
Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:50;66.4918
Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:50;66.7833
Patrol7;/NT_CPU/CPU_0/CPUprcrInterruptsPerSec;04/04/2012;11:04:50;67.3667
I try to use this code for parsing but also doesn't work
fid = fopen('CPU.csv');
tline = fgetl(fid);
u=sprintf('%c',tline);c=length(u);
id=findstr(u,';');n=length(id);
data=cell(1,n);
for I=1:n
if I==1
data{1,I}=u(1:id(I)-1);
else
data{1,I}=u(id(I-1)+1:id(I)-1);
end
end
ct=1;
while ischar(tline)
ct=ct+1;
tline = fgetl(fid);
u=sprintf('%c',tline);
id=findstr(u,';');
if~isempty(id)
for I=1:n
if I==1
data{ct,I}=u(1:id(I)-1);
else
data{ct,I}=u(id(I-1)+1:id(I)-1);
end
end
end
end
fclose(fid);
I'm not able get the last column of my csv file in data (in matlab). Could please tell me how can I able to solve my problem
'Patrol7' '/NT_CPU/CPU_0/CPUprcrInterruptsPerSec' '04/04/2012' '11:04:50'
'Patrol7' '/NT_CPU/CPU_0/CPUprcrInterruptsPerSec' '04/04/2012' '11:04:50'
'Patrol7' '/NT_CPU/CPU_0/CPUprcrInterruptsPerSec' '04/04/2012' '11:04:50'
'Patrol7' '/NT_CPU/CPU_0/CPUprcrInterruptsPerSec' '04/04/2012' '11:04:50'
'Patrol7' '/NT_CPU/CPU_0/CPUprcrInterruptsPerSec' '04/04/2012' '11:04:50'
'Patrol7' '/NT_CPU/CPU_0/CPUprcrInterruptsPerSec' '04/04/2012' '11:04:50'
'Patrol7' '/NT_CPU/CPU_0/CPUprcrInterruptsPerSec' '04/04/2012' '11:04:50'
'Patrol7' '/NT_CPU/CPU_0/CPUprcrInterruptsPerSec' '04/04/2012' '11:04:50'
'Patrol7' '/NT_CPU/CPU_0/CPUprcrInterruptsPerSec' '04/04/2012' '11:04:50'
Thanks in advance SM

답변 (0개)

카테고리

Help CenterFile Exchange에서 Large 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