We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Read data from csv-file
Page Index Toggle Pages: 1
Read data from csv-file (Read 3087 times)
Read data from csv-file
May 18th, 2010, 3:22am
 
Hi,
I'm rather new to processing and have a problem when reading data from a csv-file. I've made a simple program to visualize some statistics, but processing says that the last column is empty (which it's not).

If you press play you'll see "[22] 0.0" as last line in the log, but if you open the csv-file you can see that there is data in the 22nd column. Can someone please tell me what's wrong?

I've uploaded my sketch but since I'm not aloud to post any links in my first post, I'll be doing that in the next post.
Re: Read data from csv-file
Reply #1 - May 18th, 2010, 3:23am
 
So, here's the link to my sketch: http://www.mediafire.com/?ygmn3mor4j3
Re: Read data from csv-file
Reply #2 - May 18th, 2010, 4:00am
 
took a quick look at your source.
the problem is

  for( int j = 1; j < 22; j++ ){
     values[j] = t.getFloat( i, j );
   }


you count up to 22 (excluding 22)
you need to change it to
  for( int j = 1; j < 23 j++ ){
or
  for( int j = 1; j <= 22; j++ ){
Re: Read data from csv-file
Reply #3 - May 18th, 2010, 4:53am
 
Haven't looked at the source (too lazy to download a zip file...) so I don't know what you use to read the CSV file, but as a reminder, Java starts counting its arrays at the index 0 (zero). So, often, column 22 can appear as column 21, actually.
Re: Read data from csv-file
Reply #4 - May 18th, 2010, 5:04am
 
Thank you!!
Now it works perfectly  Smiley
Re: Read data from csv-file
Reply #5 - May 18th, 2010, 6:32am
 
PhiLho  wrote on May 18th, 2010, 4:53am:
Haven't looked at the source (too lazy to download a zip file...) so I don't know what you use to read the CSV file, but as a reminder, Java starts counting its arrays at the index 0 (zero). So, often, column 22 can appear as column 21, actually.


that was my first thought, but i edited my post as i looked at the source. was to lazy too at the beginning Smiley

btw he starts counting with 1 but thats fine as the first line is actually the name of the row.

Re: Read data from csv-file
Reply #6 - May 18th, 2010, 6:43am
 
Cedric wrote on May 18th, 2010, 6:32am:
btw he starts counting with 1 but thats fine as the first line is actually the name of the column.

Well, I thought it was about column numbers, no row/line numbers.
But the CSV library can start counting at 1, hence my disclaimer... Smiley
Page Index Toggle Pages: 1