Help removing columns from csv file

38 views (last 30 days)
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

Accepted Answer

John
John on 30 Nov 2011
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 Comments
John
John on 30 Nov 2011
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 on 30 Nov 2011
On a mac you may also be able to use importdata
A = importdata('Book1.csv')
and then index however you like

Sign in to comment.

More Answers (0)

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!