How Parse / import CSV file with mixed data types
2 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!