We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to create a sine wave for every row of data in the .csv but no matter what I try it doesn't seem to work. Do I use arrays? Can someone please tell me or show me how?
Wave wave;
Table neutral;
//A = Amplitude
//C = Horizontal Displacement
//B = Period
void setup() {
size(500, 500);
neutral = loadTable("Test.csv", "header");
println(neutral.getRowCount() + " total rows in table");
for (TableRow row : neutral.rows ()) {
//float A = row.getFloat("A");
//float B = row.getFloat("B");
//float C = row.getFloat("C");
//println(A + " : " + B + " : " + C);
for (int i = 0; i < neutral.getRowCount (); i++) {
float Ai = neutral.getFloat(i, 4);
float Bi = neutral.getFloat(i, 5);
float Ci = neutral.getFloat(i, 6);
println(Ai + " : " + Bi + " : " + Ci);
wave = new Wave(0, Ai, Bi/100, 100);
}
}
}
void draw() {
background(255);
translate(width/2, height/2);
wave.update();
}
Answers
Yes you should use an array if you have more than just a few waves. Define one with a size equal to the number of rows in your table:
Wave[] waveArray = new waveArray[neutral.getRowCount()];
The two nested loops are strange, you don't need to iterate over the rows twice. Just delete the outer loop, then you can access the current row like this:
To get the value of a column you can use
row.getFloat()
but it only has one parameter (as far as i know). So this would assign the value of the 5th column to the variable Ai:float Ai = row.getFloat(4);
Then you can create a Wave-Object and store it inside of your array:
I didn't test the code, since i don't have your csv-file, i hope it doesn't have errors.
Thank you :)
Uups.. i'm sorry, made a mistake the last code-snippet should be
waveArray[i] = new Wave(0, Ai, Bi/100, 100);
That's ok but now I seem to be getting a null pointer exception in the 2nd row of the code. Do you know why?
That is because "neutral" doesn't exist there. Just declare the array at the top:
Wave[] waveCount;
and after you load the table in line 17 you can initialize it:
waveCount = new Wave[neutral.getRowCount()];
Thank you :)