- #1

- 16

- 0

## Main Question or Discussion Point

I am using a verlet algorithm in c++ to model the motion of a satellite, and want to output position and velocity data from each timestep so that I can then read it into MATLAB and plot graphs to see how well my model matches the 'real life' graphs. so far I have at the end of each iteration:

As far as I have been taught, this should create the file height_data.dat in the same location as the c++program, but it doesn't.

I am also unsure about adding new data at each timestep without erasing previous data, and wondered if it is possible to store time, height and velocity all in one file to use with MATLAB?

Any hints on if and how I can achieve this would be greatly appreciated.

Thanks in advance

:)

Code:

```
ofstream fout; bool ok;
ok = false;
do{
fout.clear();
fout.open("height_data.dat");
if (fout.good()) ok = true;
}while (!ok);
fout<<height<<endl; //height is the variable with current position to output and store
fout.close();
```

As far as I have been taught, this should create the file height_data.dat in the same location as the c++program, but it doesn't.

I am also unsure about adding new data at each timestep without erasing previous data, and wondered if it is possible to store time, height and velocity all in one file to use with MATLAB?

Any hints on if and how I can achieve this would be greatly appreciated.

Thanks in advance

:)

Last edited by a moderator: