We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, i am facing a problem in exporting the data in .txt file: all the files i created contains the same informations (same x and y coordinates)
My goal is to collect several trials with x and y coordinates and export them in separate data files 9one for each trial). i am using PrintWirter
PrintWriter[] output = new PrintWriter[4];
in this case it created 5 output files where i can save my data, and then i would like to fill them with the x and y positions.
The files are correctly created, but they contain the same data, i.e. file number 1 contain the same x and y data of the file number 5.
here the code
void setup(){
smooth();
fullScreen();
rectMode(CENTER);
//define the output file where you want to save it
for (int i =0; i <output.length; i++){
output[i] = createWriter("/Users/Dropbox/ProcessingData/positions" + nfs(i,2) + ".txt");
}
//define the sampling frequency
frameRate(200);
}
here the part of the code with x and y coordinates
if(mousePressed){
for (int i =0; i <output.length; i++){
output[i].println(mouseY + "\t" +mouseX);
}
and this is the part where i save the data
for (int i =0; i <output.length; i++){
output[i].flush();
output[i].close();
}
any help is appreciated.
Thanks
Ivan
Answers
Obviously they contain the same data - you're writing the same data to all of them.
What exactly are you trying to do? Maybe we can help.
well, yes, they would. there's nothing in your code that treats one file any differently from the other 4.
BTW, you're creating only four writers, not 5.
Thanks for the response!
So what can i do for saving the different data that i gather form every single trial?
I started to code with processing yesterday guys, please forgive me for my naive question.
what do you mean by trial?
are you running the program multiple times and want a file for each trial? or are you running the program once and doing multiple trials?
in the former case you could open one file using the date and time in the filename. further runs would automatically use different file names.
in the latter case you could define a key to stop and start a trial and change the filename in keyPressed()
Thanks koogs, the first solution i think will suit for my case. Thanks a lot!
sorry, another question: can i use mouseReleased instead of keyPress?
this is what i wrote
How can i define the file name there?