I have done lots of googling but I have a 2D-array of type double and I want to save it to a file, so I can then plot the data using matplotlib in python, need help with saving it though please :D
@indiarose27,
It depends how you want your data filed for plotting. If you have only 4 modes then the file could be in columns something like
theta mode0 mode1 mode2 mode3
but with a lot of modes this would be impractical.
You are not consistent about the number of modes: it is 3 on line 15, but implied to be 4 on line 32. This will lead to access outside array bounds.
Do you actually need an array for U? Unless you have other plans for it, just work out a particular modal value on line 35 and write this columnar value to file (not cout) on line 36; you will need spaces or other delimiter between columns.
So a suggestion is:
- use an ofstream command to open your output file attached to a stream before any loops;
- output theta (but no linefeed) to that filestream after line 29
- for each U evaluated write immediately to file (instead of line 36)
- write a linefeed after the end of your idxMode loop.
Thankyou for this @fiji885 it worked perfectly! @lastchance for this particular case I will be using a small number of modes and U will need to be used in further calculations this plotting is more just a check/test of the code so far, but really useful suggestions for the future nonetheless so thank you for this :D