Help removing columns from csv file

17 次查看(过去 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 中查找有关 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