I want to collect data from the Android accelerometer and write it on a file. The file is stored on the SDCard and then I manually copy to the computer by adbpull comand. Then I want to analyze the values on Matlab.
What’s the best way to do? I tried writting the parameters as a string but I dont know how to read then on Matlab.
WriteOnFile(FdataAcc, String.valueOf(event.timestamp)
+ " " + mAcceleration[0]
+ " " + mAcceleration[1]
+ " " + mAcceleration[2] + "\n");
public void WriteOnFile(File filename, String data){
try{
DataOutputStream dos = new DataOutputStream( new FileOutputStream(filename,true));
//new appended stream
dos.writeChars(data);
dos.close();
}
catch(Exception e){;}
}
I also tried to write the values as float, but still I cant read on Matlab.
public void WriteOnFile(File filename, long data){
try{
DataOutputStream dos = new DataOutputStream( new FileOutputStream(filename,true));
dos.writeFloat((float)data);
dos.writeChars(" ");
dos.writeFloat((float) mAcceleration[0]);
dos.writeChars(" ");
dos.writeFloat((float) mAcceleration[1]);
dos.writeChars(" ");
dos.writeFloat((float) mAcceleration[2]);
dos.writeChars("\n");
dos.close();
}
catch(Exception e){;}
}
What’s the best way to do? Should I use Dataoutputstream to write in a file? Sensor values are floats.
Thanks in advance.
You should use the second example you showed, but don’t write the characters between the floats.
When you do fopen on matlab, make sure you put in the machine format argument. You might need to experiment with it until you get the right format, but it will work. Do
help fopento see the options.then all you have to do in order to read in all the data is
Or, if you want to read into an array:
Where M is the number of elements in each column in the array.