필터 지우기
필터 지우기

importing CSV data with multiple formats in a row into MATLAB ?

조회 수: 3 (최근 30일)
Farhan
Farhan 2014년 5월 27일
답변: dpb 2014년 5월 27일
I have to read the following PMU data into MATLAB from a CSV data file including different formats of the data.
The first two rows of my data looks like. First row is header and second row is actual data.Also i need to skip date "2014/05/26" from the first entry.
Timestamp,Test:V+:Magnitude,Test:V+:Angle,Test:I+:Magnitude,Test:I+:Angle,Eldrich2:V+:Magnitude,Eldrich2:V+:Angle,Eldrich2:I+:Magnitude,Eldrich2:I+:Angle
2014/05/26 15:27:17.140,2.4305,170.3142,0.4488,122.2368,2.9103,-129.0612,0.463,23.9783
Do you help me with a code to solve it?

채택된 답변

dpb
dpb 2014년 5월 27일
Try sotoo of--
fid = fopen('abcd.csv','r');
fmt=['%*s %2d:%2d:%2d.%3d repmat('%f',1,9)];
C = textscan(fid, fmt,'headerlines',1','delimiter',',','collectoutput',true);
fid=fclose(fid);
NB: AIRCODE, untested, salt to suit...

추가 답변 (1개)

dpb
dpb 2014년 5월 27일
Many options in Matlab; probably the simplest to code is
[dat,txt]=xlsread(yourfile);
_dat_ will be an array of the numeric data while _txt_ will contain the text in a cell
You can force into given forfmats via textscan and/or textread
  댓글 수: 1
Farhan
Farhan 2014년 5월 27일
I am using textscan for this. Code:
% to read CSV file fid = fopen('abcd.csv'); C = textscan(fid, '%s %f %f %f %f %f %f %f %f'); fclose(fid);
But its not working.
Could help me to identify the problem?

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

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by