필터 지우기
필터 지우기

Help removing columns from csv file

조회 수: 21 (최근 30일)
Jimes Tooper
Jimes Tooper 2011년 11월 30일
Hey all,
I'm new to matlab and need some quick help manipulating csv files. I have giant (1 million rows plus) csv files with 6 columns, and I need to run PSDs on only two of the columns of data. I want to extract the two specific columns of data from the big csv, put them into variables or separate csvs, and use them for calculations. Right now I'm wrestling with textscan because there are headers in these files and some of the columns contain text.
Sample of data:
Ct*0.00127405S A1(g) A2(g) A3(g) SN FCTR
1 0.027 -0.022 0.985 95 41 [Crc OK]
2 0.027 -0.022 0.985 95 42 [Crc OK]
3 0.027 -0.022 0.984 95 43 [Crc OK]
4 0.027 -0.021 0.982 95 44 [Crc OK]
5 0.027 -0.022 0.983 95 45 [Crc OK]
thank you! JT

채택된 답변

John
John 2011년 11월 30일
If you want to load in the data and pull out the third and fourth columns (just as an example) I'd do the following:
[num txt raw] = xlsread('Book1.csv');
data = cell2mat(raw(2:end,[3 4]));
csvwrite('test.csv',data)
This will pull the data out and save it into a new csv file, you could also try,
[num txt raw] = xlsread('Book1.csv');
data = num(2:end,[3 4]);
csvwrite('test.csv',data)
If you dont want to mess with cell arrays, hope it helps.
  댓글 수: 3
John
John 2011년 11월 30일
Forgot about that, thanks, if youre on mac you might want to try csvread() although this only can only import numerical data (no strings in the file).
John
John 2011년 11월 30일
On a mac you may also be able to use importdata
A = importdata('Book1.csv')
and then index however you like

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by