Agents coding work but need add on two variable data

I have try another way i’m not sure whether correct or not. This is code below

void setup() {
  size(600, 600);
  String [] data; 
  
  data = loadStrings( "Spellman.csv" );
  String [] splitNums = split(data[0], " "  );
  for (int i = 0; i < data.length; i++) 
    
    for (int j=0; j < splitNums.length; j++) {
  println("there are " + data.length + " data");

 {
     println("" + i + "," + j + "=> " + splitNums[0]);
   }
  }
    }

The output result is

there are 4382 data
4332,1=> MICe
there are 4382 data
4332,2=> MICe
there are 4382 data
4332,3=> MICe
there are 4382 data
4332,4=> MICe
there are 4382 data
4333,0=> MICe
there are 4382 data
4333,1=> MICe
there are 4382 data
4333,2=> MICe
there are 4382 data
4333,3=> MICe
there are 4382 data
4333,4=> MICe
there are 4382 data
4334,0=> MICe
there are 4382 data
4334,1=> MICe
there are 4382 data
4334,2=> MICe
there are 4382 data
4334,3=> MICe
there are 4382 data
4334,4=> MICe
there are 4382 data

Help me sir.

Close enough, I guess.

void setup() {
  size(600, 600);
  String [] data; 
  data = loadStrings( "Spellman.csv" );
  println("There are " + data.length + " lines of data.");
  for (int i = 0; i < data.length; i++) {
    // Tell which line we are looking at now.
    println( "Now looking at line #" + i + ", which is " + data[i] );
    // Parse this line using split().
    String[] numbers_on_this_line = split( data[i], ',' );
    // Show every number we found on this line.
    for( int j=0; j < numbers_on_this_line.length; j++){
      println( "" + i + ", " + j + " => " + numbers_on_this_line[j] );
    }
    float a = float(numbers_on_this_line[0]);
    float b = float(numbers_on_this_line[1]);
    float c = a + b;
    println( "The sum of the first two numbers on this line is " + c );
  }
}

Understand this example. The for loop that uses i is looping over each LINE in the file. The for loop that uses j is looping over how many numbers we found on that line.

I can then pick off the first two numbers that were found on the line, convert them into floating point numbers, and then store them in the variables a and b. Now that they are numbers - not Strings - adding them together results in a number (called c) that is their sum.

Of course, you don’t want to add the numbers together. You want to make use of them by passing them into a new Ball object.

1 Like

As per guide from you, i have partially done the coding which is

void setup() {
  size(600, 600);
  String [] data; 
  
  data = loadStrings( "Spellman.csv" );
  println("There are " + data.length + "lines of data."); 
  for (int i = 0; i < data.length; i++) {

  println("Now looking at line -> " + i + ", which is " + data[i]);

  String [] splitNums = split(data[i], ',');
   
  for (int j=0; j < splitNums.length; j++){
    println("" + i + "," + j + " => " + splitNums[j]);
    
    float a = float(splitNums[0]);
    float b = float(splitNums[1]);
  }
  
 }
} 

And the output result is

Now looking at line -> 4216, which is 0.30645,0.09907
4216,0 => 0.30645
4216,1 => 0.09907
Now looking at line -> 4217, which is 0.30645,0.08708
4217,0 => 0.30645
4217,1 => 0.08708
Now looking at line -> 4218, which is 0.30645,0.09907
4218,0 => 0.30645
4218,1 => 0.09907
Now looking at line -> 4219, which is 0.30645,0.02179
4219,0 => 0.30645
4219,1 => 0.02179
Now looking at line -> 4220, which is 0.30645,0.08708
4220,0 => 0.30645
4220,1 => 0.08708
Now looking at line -> 4221, which is 0.30645,0.13535

Why i can’t view all output result in console? but i view certain output result in console.
What should do then can view all console output result?

How should i merge ball class object coding with split coding? Guide me please?

The console doesn’t keep track of every line ever printed. It’s only going to go back a few thousand lines. Usually there is no point in tracking more than that.

In any case, it should be obvious that the loop is processing every line of data in the file.

Now that you have the first two values from the file stored in variables, it is up to you to work out a way to use them. Since you want to make your Ball objects do something or look different depending on these values, it makes sense to pass these values into the constructor for your Ball class. In previous code you have posted, you have already done this sort of thing with the origin variable. You must understand this because it’s code you already had… so you either wrote it and already understand it (great), or you got some example code and then took the time to understand it, right?

You’re also going to need to reconcile the number of Ball objects you want. Previously, you had 100 of them. Are you now going to have one for each line in your CSV file (that is, 4000+ Balls)? Or are you going to stick with 100 of them?

In short, you need to make this loop:

  for (int i = 0; i < 100; i++) {
    Vec3D origin = new Vec3D (random(width), random(130), 0);
    Ball myBall = new Ball(origin);
    ballCollection.add(myBall);
  }

and this loop:

for (int i = 0; i < data.length; i++) {

  println("Now looking at line -> " + i + ", which is " + data[i]);

  String [] splitNums = split(data[i], ',');
   
  for (int j=0; j < splitNums.length; j++){
    println("" + i + "," + j + " => " + splitNums[j]);
    
    float a = float(splitNums[0]);
    float b = float(splitNums[1]);
  }
  
 }

be the same loop!

1 Like

Ball objects coding i have make partially with guide from YouTube video. I’m understand that ball class coding. Let’s said i run the ball object coding it’s some kind like this video https://www.youtube.com/watch?v=upfQATibeCU .

I’m think have to make it for each line in CSV file. I need suggestion from you sir?

The code from inside the first loop adds a new Ball object.

Every time the second loop happens, you’re finding two numbers from a line in your file.

You want to use those two numbers to create a Ball.

Thank you lot sir. First thing i’m look at one of the link: https://www.broadinstitute.org/news-and-publications/mine-detecting-novel-associations-large-data-sets .There make it something neural scheme. So that why, first i make it something ball class coding. Then need should insert dataset csv file into ball class coding. That’s my idea but im not sure it’s work or not. Sir any suggestion from your side? Help me.

Sir i need your guide me on this link beside https://youtu.be/EZgiYYxUT74. Is it possible to make it like this sir using Processing 3? For example data which is between 0.3123 until 0.3914 this kind range its make into one portion of group and another data which is between 0.5012 until 0.5987 this kind range value make into another portion of group ball. From that video i have understand some kind like that. Please help me sir?

If you want to map sub ranges of values to single value each, use a cascade of if statements:

if (x > 0.3123 && x < 0.3914){
  y = 1;
}
else if (x > 0.5012 && 0.5987){
  y = 2;
}

If you want to map ranges of values to other ranges, you can use map() or lerp():

if (x >= 0.3123 && x < 0.3914){
  y = map(x, 0.3123, 0.3914, 0, 1);
}
else if (x >= 0.5012 && x < 0.5987){
  y = map(x, 0.5012, 0.5987, 1, 2);
}
else if ( ...