csv file split error ","

2 views (last 30 days)
Halil Can
Halil Can on 28 Oct 2021
Edited: Halil Can on 28 Oct 2021
I have a csv file with 1.7 million rows and 37 columns. I want to split it into 2 csv files, 850k rows each.Please give me your advice.After the code I wrote, it looks like the following.All appear in one column. Where am I doing wrong?
  2 Comments
Halil Can
Halil Can on 28 Oct 2021
csvwrite('test.csv',input,850000,37)

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 28 Oct 2021
It looks to me like the issue is that your column offset is 37.
  • The column offset indicates the number of columns to skip before writing the numeric data. col is zero-based, so that col = 0 instructs MATLAB to begin writing in the first column of the destination file. Skipped columns are separated by commas.
By telling it to skip 37 columns, you get 37 commas with nothing between, and it starts writing the 38th column. However, you only have 37 columns of data, so the result is a csv file with nothing but commas. See here.
Try this instead
csvwrite('test.csv',stampstsextport,850000,0)
Also note that csvwrite is not recommended. Consider using writematrix instead.
writematrix(stampstsexport(850000:end,:),'test.csv')
Also note that both of these examples will give you a single file. You would need to have code to create the file of the first 850k rows.

Community Treasure Hunt

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

Start Hunting!