Fourier transform to decompose a signal into multiple frequencies - scipy

I want to decompose a signal into multiple discrete frequencies.
^ Here the top wave is composed of the bottom two discrete waves. It is my understanding that it is possible to use fourier transforms to separate that top signal into multiple underlying frequencies. I want to obtain those separate frequencies (D294, A440) given my 1d array below.
Import Data: I have a 1D array of temperature readings over 1575 timesteps.
import numpy as np
temp_arr_1d = np.array([10. 7.4 7.16666667 8.66666667 6. 7.
7. 8.85714286 14. 11. 15.71428571 14.
15.83333333 12.83333333 14.71428571 13.83333333 16.5 13.83333333
12.5 11.28571429 11.2 9.5 14. 13.83333333
12.25 12.66666667 12.85714286 14.83333333 14.125 14.71428571
16.2 16. 16.28571429 18. 17.42857143 16.625
16.66666667 15.6 14. 15.42857143 15.25 15.875
15.33333333 16.28571429 17.33333333 19.16666667 14.42857143 13.66666667
15.6 15.85714286 17.71428571 20. 20.5 17.42857143
16.85714286 16.875 17.85714286 20.8 19.42857143 17.33333333
19. 19.33333333 17.6 20.875 20.85714286 23.42857143
24.16666667 25.42857143 23.14285714 24. 23.5 21.5
22.33333333 24.16666667 20.33333333 22.66666667 23.42857143 22.5
29.16666667 23.83333333 25.25 27.375 27. 23.5
24.14285714 21. 22.42857143 21.25 23.5 23.2
25.375 25.16666667 26.2 24.6 25.6 25.85714286
29.14285714 28.71428571 30.16666667 30. 30. 28.85714286
30.2 28.25 28.25 32.125 29.2 30.28571429
28.28571429 30.625 27.66666667 27.375 28.625 30.28571429
31.14285714 29.875 31.14285714 30.57142857 32.125 31.14285714
31.85714286 29.83333333 28.57142857 32.85714286 32.625 32.75
32.875 34.5 34.28571429 34. 30.75 29.85714286
31.71428571 32.28571429 33. 33. 32.83333333 31.4
35.33333333 36.4 36. 36.75 37.5 38.42857143
38.71428571 37.8 35.85714286 35.33333333 34.14285714 32.2
33.625 32. 32.4 35.6 35.85714286 37.16666667
31.28571429 34. 34.2 36.16666667 36.625 30.16666667
34.14285714 29.83333333 30.14285714 30.71428571 27. 26.875
28.4 29.85714286 33. 34.83333333 35.6 35.16666667
33.14285714 30.57142857 30.66666667 31.42857143 31.5 33.25
32.83333333 33.85714286 33.14285714 31.57142857 32.375 32.8
31. 31.16666667 29.83333333 29. 29.75 32.5
28.875 31.75 30.75 31.75 29.875 31.125
31.75 30.5 26.83333333 28.2 29.5 31.85714286
29.71428571 28.33333333 30. 30.14285714 32.28571429 31.
30.5 28.83333333 30. 31.57142857 32.5 32.5
29.5 27.16666667 28.375 28.5 27.16666667 29.42857143
30. 29.5 30.75 29.66666667 27.71428571 26.6
27.42857143 28.33333333 28.16666667 27.375 28.33333333 29.16666667
31.28571429 32. 29. 32. 32.14285714 30.14285714
31.5 29.16666667 29. 30. 31.85714286 32.75
31.71428571 31.66666667 30.57142857 30.83333333 28. 31.
29.66666667 30.85714286 31.16666667 31.14285714 30.5 31.625
29.66666667 29.25 29.14285714 29.8 28.66666667 25.2
28.33333333 30.28571429 30.75 28.57142857 28.2 29.
30. 28.14285714 26.85714286 28.28571429 29.2 28.6
24.83333333 28.5 29.75 29.71428571 29.2 30.83333333
29.42857143 23.85714286 26.14285714 27.16666667 27.71428571 25.85714286
26.42857143 26.85714286 26.33333333 24.57142857 24.33333333 24.875
27.8 25. 23.85714286 22.8 23. 22.875
22.66666667 23. 22.85714286 23.66666667 23.42857143 21.625
20.625 21.16666667 18.83333333 20.57142857 20.14285714 18.
19.85714286 16.83333333 18.85714286 16.57142857 17.75 17.625
17. 16.625 15.57142857 18.5 17.875 18.25
17.875 17.625 18.14285714 19.125 21.25 21.25
19.125 18.625 17.75 17.875 18. 17.25
17.5 17.14285714 17.14285714 16.125 16. 16.5
16.125 15.5 16.625 17.75 17.14285714 16.14285714
15.5 15.25 14.75 14.875 16.125 15.375
14.75 15.25 14.25 13.5 13.66666667 12.125
11.875 10.875 10.57142857 12.375 14.5 13.375
11. 12.5 12.875 12.375 11.42857143 12.14285714
11.875 12.83333333 12.375 12.125 12.875 14.
14.875 12. 12.28571429 12. 12.5 14.5
14.625 13.57142857 15.25 15.625 13.875 11.75
14.375 16.625 16.625 14.875 14.5 14.75
14. 15.25 18.42857143 18.85714286 17. 18.5
19.625 13.625 12.875 12.625 13.375 13.25
15.25 13. 12.375 13.5 15.125 15.25
15.125 16.125 17.125 16.625 16.5 16.375
18.125 18.75 18.625 15.625 16.14285714 16.125
17.875 18.75 18.875 18.375 18.5 19.875
22. 20. 20.71428571 20. 19. 19.625
21.625 23.125 26.25 24.85714286 21.75 21.5
22.5 25. 22.75 22.375 24.625 25.125
23.5 24.42857143 25.875 24.125 24.125 24.875
26.75 25. 25.85714286 27.375 30.125 27.25
25.75 25.75 26.375 28.14285714 29.125 26.875
27.625 29. 27.125 26.375 24.25 25.625
27. 28. 29.375 29.125 29.375 30.625
31.5 30.625 31.5 32.125 33.25 34.875
34.375 31.75 31.875 29.75 29.57142857 31.75
31.375 30.5 30. 29.625 28. 25.25
26.875 29.5 31.125 29.875 31.5 32.375
31.125 33. 33.25 34.625 31.5 31.5
30.125 31.875 33.625 35.25 33.125 34.625
32.75 32.75 34.875 35.25 36.875 37.5
38.5 37.625 37.875 37.25 37.625 32.875
30.25 30.5 33.875 36.375 36.875 33.875
35.75 38. 36.875 34.5 32.125 33.
32.25 32.5 34.75 34.875 33. 32.
31.375 29.5 28.875 31.38888889 34.70588235 30.625
34. 35. 36. 36.125 36.625 35.875
31.625 32.375 33.125 32.625 30.75 27.25
29.875 30.875 32.125 31.625 30.625 30.5
30.75 32.5 31.71428571 30. 30.25 31.875
32.5 33.25 30.125 31.5 30.5 29.75
32.125 31.125 31. 29.23529412 28.5 31.125
32.125 32.125 30.375 31.125 30.42857143 31.375
31.875 33. 33.25 32.5 33. 33.125
33.125 33.875 34.125 33.85714286 29.625 30.375
28.625 27.625 29.42857143 29.25 28.625 27.875
26.5 28.5 31. 31.25 31. 28.75
26.57142857 28.5 29.375 29.125 29.625 30.625
30.625 30.5 31. 31.125 30.5 30.625
31. 29.625 30. 30. 30.5 30.25
30.5 30.625 30.42857143 30.375 30.5 31.
30.625 30.625 31. 28.75 27.625 27.125
25.71428571 26. 27.625 24.5 24.5 23.
25. 24. 23.75 24.75 25.625 25.75
25.25 25.5 25.25 25.125 24.875 25.125
24.75 23.875 23.375 22.5 22.875 23.375
23.625 22.75 23. 24. 23.875 24.125
21.375 19.25 19.625 18.5 18.375 18.625
18.25 17.75 17.625 17.5 20.375 18.25
19.875 17.125 16.875 16.5 19.625 18.125
19.375 20.25 19.75 20. 21.375 25.
21.25 17.75 18.25 17.25 17. 15.28571429
21.5 19.625 17.5 16. 16.875 16.625
17.75 12.875 11.75 11.75 11.25 9.5
9.375 9.625 9.875 9.25 10.75 10.375
9. 11.125 11.625 12.375 14.75 14.875
15.125 14.125 14. 12. 9.625 10.
10.625 11.125 11. 10.625 12.25 12.
12.375 13. 13.5 13. 13.75 13.375
13.25 12.625 14.625 12.375 13.25 13.75
13.25 11.71428571 11.5 12.75 13.75 15.
17.375 16.75 14.625 14.625 15.125 15.875
16.625 16.875 15.75 16. 15.5 17.25
19.375 18.875 20.625 21.14285714 21.25 22.75
22.75 21.875 22.14285714 21.5 22.875 23.125
20. 19.25 21.25 17.375 17.5 16.25
16.75 18.75 20. 18.375 19.5 18.125
17.75 18.25 20.5 21.375 21.5 17.625
19.85714286 20.875 20.25 21.125 22.5 24.875
25.125 24.75 25.75 26.625 28.5 27.375
27. 25. 23.5 25.25 26.42857143 28.71428571
24.5 21. 23.57142857 25. 23.75 25.625
26. 27.125 28.25 24.375 24.75 26.25
27.625 25.25 28.125 30.125 32.125 32.875
31.75 30.75 30.75 31.125 30.5 28.75
30.125 31. 31.25 32.625 31.25 30.125
31. 30.875 32.125 34.125 35.42857143 34.125
35.125 35.125 34. 33.125 27.75 29.625
28.5 30. 33.25 35.375 31.5 33.125
35.625 36.25 37.375 36. 37.75 35.25
33.75 34.75 35.125 32.25 34.25 29.375
31.625 28.625 31.875 32.625 33.375 35.
36.5 37.625 36.625 35.625 35.875 31.125
27. 31. 32.375 33.875 35.125 35.875
33.125 30.375 32.125 31.5 37.25 26.625
31.125 32.625 34.25 31.125 30.875 32.
33.75 33. 34.125 35.71428571 27.875 28.125
31.25 29.625 26.625 25.5 25.5 29.875
30.875 33.375 31.75 30.75 29.5 30.125
29.125 31.375 32.25 32.125 32. 30.85714286
30. 29.625 29.5 28.5 29. 29.
28.25 29.625 31.5 29.42857143 29.59375 29.5
29.25 28.875 27.375 30.375 28.375 30.75
32. 30.875 28.5 28.625 30.75 29.125
31.25 30.75 29.375 30.25 29.875 30.75
32. 32. 32.5 32. 32.25 32.625
31.85714286 32.125 31.875 31.625 32. 30.875
31.25 31.5 31.625 31. 31.25 30.75
32.14285714 32.125 31.875 33. 32.375 31.375
31. 30.625 29.14285714 30.125 30.25 28.625
28.25 28.5 29.25 28.71428571 28.25 29.
29. 28.125 28.28571429 30. 29. 28.875
28.375 28.625 28.375 28.5 28.5 28.57142857
29.25 29.5 28.125 27.5 27.875 28.
26.85714286 28.14285714 27.71428571 26.5 24.75 24.
24.875 26.375 25.625 24.75 20.875 22.125
22.375 22.375 22.875 23.375 24. 23.75
22.125 22.875 21.875 21.875 21.75 22.75
21.875 21.875 22.375 22.375 22.5 21.875
19.875 18.5 18.5 18.5 18.75 18.625
17. 18.5 19.375 20. 18.5 18.75
18.125 19.5 19.25 18.125 17.625 17.625
17.5 17.125 17.625 18.42857143 18.375 19.
17.25 13.25 12.875 13.25 13.125 13.
12.25 12.875 12.375 11.75 12.625 12.
12.5 11.25 11.5 12.75 15.375 17.125
16.375 15.5 15. 14.71428571 14. 14.375
15.75 15.83333333 17.375 17.125 15.5 15.85714286
15.625 15.75 18. 18.26666667 15.5625 13.
13.6 14. 13.26666667 12.35714286 12.06666667 12.1875
11.73333333 14.4375 11.1875 11.66666667 14.5625 17.58333333
16.85714286 19.5625 20.14285714 17.375 15.84615385 15.26666667
13.125 16.36363636 12.66666667 15.33333333 15.625 17.09090909
17.76923077 18.13333333 19.6875 19.2 17.06666667 17.64285714
17.6 18.21428571 18.71428571 19.46666667 23.15384615 23.625
21. 21. 21.42857143 21.6875 22.5625 22.8
22.8 23. 23.875 24.91666667 24.93333333 26.
27.3125 23.93333333 22.8125 23.71428571 23.42857143 24.
25.5625 25.06666667 24.5625 24.25 22.375 24.06666667
23.9375 26.3125 26.1875 26.78571429 27.13333333 26.625
25.0625 26.2 28.13333333 29.875 24.66666667 26.25
25.93333333 27.125 29.57142857 30. 30.57142857 32.3125
33.3125 32.8125 32.3125 31.375 29.93333333 29.26666667
30.73333333 32.25 29.8 30.2 31.75 33.125
33.625 35.6875 34.66666667 34.625 34. 34.0625
34. 33.25 31.91666667 31.3125 31.75 33.4375
33.125 34.15384615 34.07142857 33.0625 34.6875 38.
35.5 33.71428571 30.6 31.4375 33.3125 35.13333333
33.53333333 34. 32.5 35.375 37.29411765 36.5625
37.25 37.21428571 37.5 37.75 37.375 37.4
36.13333333 36.8 32.21428571 31.52631579 33.2173913 35.26923077
38.27272727 36.0625 31.5 26.8125 32.64285714 36.
37.5625 37.5625 38.2 36.16666667 35.42857143 34.625
36.07142857 35.73333333 36.13333333 33.4375 35.5 36.
32.625 34.73333333 33.5 34.1875 35.85714286 35.625
30.9375 32.875 33.125 33.84615385 36.4375 35.42857143
34.86666667 34.3125 30.78571429 35.375 35.46666667 32.125
28.4 29.5625 30.6875 33.25 33.26666667 33.5
30.8 33.25 32.5625 31.5 30.5 31.25
30.4375 31. 27.125 28.125 27.66666667 32.3125
34.1875 34.13333333 34.125 31.875 31.4375 31.9375
30.3125 28.3125 29.53333333 27.375 27.33333333 29.26666667
29.125 30.6875 32.5625 33.11111111 33.8 30.06666667
33.11764706 33.80952381 31.61538462 32. 28.10714286 29.03571429
30.32142857 28.93333333 31.67857143 31.33333333 29.92857143 29.88888889
32.07142857 33.18518519 31.59259259 32.18518519 31.48 30.17857143
31.52 31.22222222 31.78571429 33.4 29.57142857 30.04
27.25925926 27.96 30.73913043 30.89473684 31.69230769 31.07692308
30.375 31.1 31.91666667 30.55555556 31.23076923 31.
31.64285714 32.53333333 30.85714286 31.72727273 31.4 32.30769231
32.25 32.375 33.44444444 33.36 30.03703704 31.
31.24 31.13043478 31.48 32.18518519 32.44 32.22727273
32.21428571 32.54166667 32.81481481 33.26923077 30.55555556 28.83333333
30.7037037 30.96 30.6 30.92 29.77777778 29.66666667
29.57142857 29.96296296 29.75 27.74074074 28.42857143 28.6
28.5 28.92592593 29.07692308 28.40909091 29.33333333 27.5
28.5 28.04 27.57692308 26.55555556 25.51851852 25.81481481
24.82608696 24.53846154 24.38461538 23.72727273 25.64 24.81481481
23.11538462 22.92592593 24.54545455 23.73076923 23. 23.51851852
23.92 23.53846154 24.2962963 23.34615385 22.24 21.76923077
21.73076923 21.73076923 20.66666667 22.25 21.53846154 22.57894737
22.82608696 21.42105263 23.6 24.29411765 23.63636364 22.45454545
21.61111111 19.86956522 19.75 19.20833333 21.20833333 18.9
18.63636364 18.53846154 18.25 16.9 19.41666667 16.44444444
20.04166667 19.90909091 19.05 18.55555556 18.16666667 15.83333333
17.5 16.08333333 17.85714286 19.8 18.05 17.28571429
15.55 17.31818182 14. 17.14285714 16.85 17.2173913
15.23809524 14.0952381 15.05263158 15.91304348 18.5 17.11111111
18.7 18.38888889 19.31818182 14.70833333 15.68421053 14.57142857
12.11111111 11. 11.78947368 13.23529412 13.2 16.43478261
14.65 11.72222222 13.04166667 14.61904762 15.26315789 15.39130435
18.44 18.11764706 18.34782609 21. 16.17857143 16.5
14.86363636 15.66666667 16.44444444 16.125 15.25 17.09090909
15.63636364 18.7 18.63157895 16.88888889 15.125 15.7
15.375 14.66666667 15.625 16.25 16.33333333 16.875
17.57142857 20.25 21.3 21.125 22.36363636 23.375
21.83333333 19.125 18.625 19.125 19. 18.75
19.875 23.33333333 24.46153846 23.75 20.5 19.125
19.75 20. 22.625 21.54545455 20.78571429 19.9375
18.53333333 17.375 17.44444444 18. 19.875 24.
20.9 24.69230769 24.66666667 23.33333333 25. 27.25
28. 28.91666667 26.5 29.1 29.5 29.88888889
31. 29.28571429 30.625 31.375 29.75 30.5
30.93333333 29.23076923 31.22222222 27. 25.625 27.125
27.85714286 29.25 29.25 29.66666667 30.5 31.22222222
31. 32.55555556 34. 33.5 34.5 34.25
32.9 32.875 32. ])
temp_arr_1d.shape
(1575,)
Run the transform
https://numpy.org/doc/stable/reference/routines.fft.html
>>> np.fft.fft(temp_arr_1d).shape
(1575,)
How do I do this?

FFT gives you spectral + phase data.
The code to obtain the spectrum:
import numpy as np
import matplotlib.pyplot as plt
temp_arr_1d = np.array(...)
# transfrom and shift to get contiguous data
transform = np.fft.fftshift(np.fft.fft(temp_arr_1d))
# squared modulus is the spectral power
spectral_power = np.abs(transform)**2
# plotting routines
plt.figure(figsize=(10,10))
plt.plot(spectral_power)
plt.xlim(770,810)
plt.show()
Your signal contains one very strong frequency + two sidebands. See figure below.
What are you trying to achieve?

Related

How to average data per week?

I hope someone could help me. I am starting to use R.
1st of all I would like to know if it is possible to determine the week of the year with the day my data was collected using R. I made this manually, but takes long time and increases the chance of my making a mistake...
I also am interested in getting the average of each week. For example, I have 2 data points in week 21.
An example of my data:
enter image description here
Week Date Class 1 g/plant Total g/plant 10 berry weigh Brix
21 26/05/2022 34.53571429 34.53571429 25.7 11.55
21 28/05/2022 35.39285714 39.25 27.1 10.98
22 31/05/2022 41.17857143 41.17857143 22.8 11.8
22 03/06/2022 57.60714286 57.60714286 22.2 10.91
23 06/06/2022 23.67857143 23.67857143 26.4 12.3
23 09/06/2022 23.60714286 24.14285714 24.7 12.63
24 14/06/2022 18.82142857 19.78571429 26.4 12.8
24 18/06/2022 20.78571429 20.78571429 30 12.05
25 21/06/2022 3.178571429 3.25 22.2 10.3
25 23/06/2022 0 0 0 0
25 25/06/2022 0 0 0 0
26 28/06/2022 0 0 0 0
26 01/07/2022 0 0 0 0
27 05/07/2022 0 0 0 0
27 09/07/2022 0 0 0 0
28 12/07/2022 0 0 0 0
28 14/07/2022 0 0 0 0
28 16/07/2022 0 0 0 0
30 26/07/2022 50.89285714 50.89285714 27.6 9.85
30 29/07/2022 19.39285714 19.39285714 19.1 10.58
31 02/08/2022 68.57142857 68.57142857 25 8.91
31 06/08/2022 58.75 58.75 24.9 8.81
32 09/08/2022 46.57142857 46.57142857 17.7 8.92
32 11/08/2022 24.25 24.25 17.2 9.77
32 13/08/2022 32.14285714 32.14285714 16 20.41
33 16/08/2022 53.14285714 53.14285714 19.7 10.09
33 20/08/2022 57.96428571 59.25 17.8 9.49
34 25/08/2022 28.10714286 28.10714286 18 9.99
35 30/08/2022 81.03571429 81.60714286 19.6 10.89
35 02/09/2022 22.53571429 22.53571429 14.8 10.04
36 06/09/2022 36.53571429 38.96428571 17.9 11.18
36 09/09/2022 24.5 25.71428571 17.3 10.48
37 16/09/2022 57.35714286 60.96428571 21.2 12.21
38 21/09/2022 5.142857143 7.142857143 13.5 11.58
39 30/09/2022 29.9047619 31.76190476 16.4 15.49
40 07/10/2022 22.9047619 24.47619048 16.4 15.12
41 12/10/2022 14.61904762 14.85714286 12.5 14.14
42 19/10/2022 15.57142857 17.04761905 15.6 14.24
43 26/10/2022 20.14285714 22.0952381 17.6 12.32
Thank you in advance!
Alex
I am interested in getting the average of each week. For example, I have 2 data points in week 21.
I am not sure what to do.

How can i use a text file to create a figure in matlab?

I have row data in a text file that looks like this:
2.40 2.22 5.48 -5.93 -3.67 5.84 0.70 1.44 3.26 -12.27 -5.65 0.81 -1.17 5.83 5.50 -1.67 7.10 -7.14 1.25
1.47 15.78 -10.79 0.70 -1.58 3.77 4.67 3.62 -2.19 3.43 2.82 -0.52 -1.61 6.30 3.57 6.06 8.07 2.03 2.95
2.64 -3.78 -12.95 2.73 -2.18 -1.16 0.35 6.90 5.57 -1.64 1.45 8.78 2.27 -1.03 0.91 0.64 0.02 1.93 2.14
6.19 1.87 12.23 -7.71 14.92 1.30 -1.04 0.93 6.75 4.91 21.72 4.22 4.02 -0.16 2.06 1.89 0.23 0.91 4.36
-0.03 -2.78 0.79 -5.98 -0.18 -1.19 5.57 -7.95 1.95 2.86 2.85 -6.89 -0.53 -6.59 2.14 3.75 1.22 2.49 1.72
5.52 -4.71 -5.38 -7.50 4.21 3.38 4.14 0.92 -2.23 -13.98 0.98 1.45 -3.50 3.04 -5.04 -1.35 -6.37 -3.57 -1.96
-0.62 0.86 -1.99 -10.95 7.00 -1.85 5.00 -1.33 -1.50 -0.69 10.36 4.60 -4.69 4.19 7.17 -0.74 5.00 5.53 -3.02
1.91 1.85 -7.72 -2.67 3.62 -0.52 -1.13 4.40 -2.64 1.26 3.40 -3.17 -10.48 -2.22 -1.04 0.64 -5.93 2.47 -0.86
-0.12 -8.24 -11.59 -15.03 -3.21 3.27 5.67 5.21 -0.40 -12.33 0.62 8.42 -5.89 3.03 4.07 -0.16 -4.43 1.78 2.12
8.09 -3.20 6.90 12.89 8.92 -0.01 -1.97 4.53 -1.92 -17.77 4.76 0.04 8.83 -1.41 1.73 1.55 6.93 -0.95 0
11.80 -6.92 11.79 12.82 0.42 5.93 4.01 -0.94 -6.49 -2.12 -0.01 1.43 -1.41 3.09 2.27 3.36 3.63 1.44 0
16.23 -2.27 1.66 -12.50 3.10 0.66 5.93 8.31 -2.00 3.69 1.91 5.86 1.11 2.05 2.09 1.06 -4.03 2.92 0
Each column represents a year from 1999 to 2017 in order (going from left to right) and each row represents a month from Jan to December in order (going top to bottom).
I have to write a code that transforms this data to a figure. The code needs to be as general as possible so that any other data can be added and still run the code. The biggest problem I'm having is how I have to assign the columns to years and the rows to months.
The following is a link to a pdf file containing the figure and the data file
https://www.dropbox.com/s/bgzg6lbpr3t0ib9/Inl%C3%A4mningsuppgift2_HT17%20%281%29.pdf?dl=0
The easiest way to import the data in a general way would be to use the graphical Matlab import tool
uiimport
select output type as "Numeric Matrix"
then you have your data in this example as 12x19 double
rehape the array to a vector can be done in this case just by data(:)
figure;plot(data(:))

Create a contour plot from 3 vectors

I'm trying to create a contour plot from this data:
pH D Tur
5.10 3 79.18918919
5.50 6 92.97297297
5.00 0 50.09009009
5.00 6 90.36036036
5.10 9 91.08108108
5.10 12 89.18918919
5.10 15 83.6036036
5.00 18 91.26126126
5.00 21 81.26126126
5.00 24 90.99099099
5.00 27 91.44144144
5.00 30 90.45045045
6.00 0 43.42342342
5.64 3 81.8018018
5.50 9 92.16216216
5.50 0 44.68468468
5.40 12 92.34234234
5.50 15 92.25225225
5.50 18 91.62162162
5.50 21 90.81081081
5.50 24 91.8018018
5.50 27 92.52252252
5.50 30 90.36036036
6.10 3 81.98198198
6.00 6 93.51351351
6.00 9 94.77477477
6.10 12 95.04504505
6.00 15 94.68468468
5.90 18 94.05405405
6.00 21 94.68468468
6.00 24 94.41441441
6.00 27 93.69369369
6.00 30 94.5045045
6.50 0 41.08108108
6.50 3 76.03603604
6.50 6 87.92792793
6.60 9 94.32432432
6.50 12 94.77477477
6.50 15 94.32432432
6.50 18 94.95495495
6.50 21 94.41441441
6.40 24 93.33333333
6.40 27 94.41441441
6.40 30 94.14414414
7.00 0 41.17117117
7.00 3 61.71171171
6.90 6 84.05405405
6.90 9 89.72972973
6.90 12 90.81081081
6.90 15 91.53153153
6.90 18 91.44144144
6.86 21 91.53153153
6.86 24 91.98198198
6.86 27 90.81081081
6.90 30 92.79279279
7.44 3 65.85585586
7.50 6 79.72972973
7.50 0 59.00900901
7.50 9 81.35135135
7.50 12 79.00900901
7.50 15 81.98198198
7.50 18 83.69369369
7.50 21 81.17117117
7.50 24 80.09009009
7.30 27 89.63963964
7.50 30 81.98198198
I've imported the data as 3 different vectors: pH, D, and Tur
I created a mesh and griddata and plot the contour
[X Y]=meshgrid(pH,D);
Z=griddata(pH,D,Tur,X,Y);
contourf(X,Y,Z)
I was hoping something like that:
But I'm getting this:
You need to sort your inputs to meshgrid first:
[X, Y] = meshgrid(sort(pH), sort(D));
Z = griddata(pH, D, Tur, X, Y);
contourf(X, Y, Z);
Or another alternative is to use unique to both sort and remove redundant values from pH and D, reducing the size of the matrices produced by meshgrid:
[X, Y] = meshgrid(unique(pH), unique(D));
Z = griddata(pH, D, Tur, X, Y);
contourf(X, Y, Z);
And both of the above options give the same graphical result:

How can I extract row whose element in 1st column is the maximum?

I have following data:
eg1:
5.34 -32.82 0.71
7.65 -32.74 0.67
9.89 -32.76 0.69
13.81 -32.74 0.68
17.20 -33.27 0.71
22.83 -33.28 0.61
27.10 -33.40 0.67
29.22 -33.20 0.66
Output: Comparing max(:,1), I need to extract 29.22 -33.20 0.66
Eg2:
4.58 -49.98 1.27
5.84 -50.13 1.23
7.33 -50.15 1.24
10.39 -50.18 1.28
13.60 -50.03 1.27
17.73 -50.07 1.34
10.99 -49.90 1.41
10.81 -49.76 1.43
Output should be:17.73 -50.07 1.34
EDIT:
4.58 -49.98 1.27 5.31 -38 1.12
5.84 -50.13 1.23 7.65 -38 1.11
7.33 -50.15 1.24 9.88 -38.01 1.12
10.39 -50.18 1.28 13.78 -38 1.12
13.6 -50.03 1.27 17.2 -38.07 1.13
17.73 -50.07 1.34 22.8 -38.06 1.14
10.99 -49.9 1.41 27.19 -38.06 1.14
10.81 -49.76 1.43 29.29 -38.02 1.13
OUTPUT: executing a(a==max(a(:,1)),:) for each consecutive column
17.73 -50.07 1.34
29.29 -38.02 1.13
A=sortrows(A);
A(end,:)
ans =
29.2200 -33.2000 0.6600
sortrows sorts your matrix row-wise, with the maximum element of row one obviously at the end. Therefore, extract the endrow and you're done.
Even faster without sorting your dataset:
A(A==max(A(:,1)),:)
This finds the entry in the first column where A attains its maximum and uses that as a logical index to extract the full row.

how to get the row in some column in one table

I have some problem with query in postgresql
I have 7 column in one table
Year Month Date Rain Tmax Tmin ID Stat Location
1996 1 1 3 25.4 20 98212 air
1996 1 2 1 25.4 19.6 96112 land
1996 1 3 -9999 24.6 19.2 97110 sea
1996 1 4 1 22 19 98212 air
1996 1 5 -9999 24.4 19 96112 land
1996 1 6 -9999 24.2 18.6 98212 air
1996 1 7 1 24.2 19.4 96112 land
1996 1 8 -9999 24.8 20 97110 sea
1996 1 9 -9999 25 19.6 97110 sea
I want to query the row in table and get output to the text file with name (ID-Stat Location)
the expected output :
98212-air.txt
Year Month Date Rain Tmax Tmin
1996 1 1 3 25.4 20
1996 1 4 1 22 19
1996 1 6 -9999 24.2 18.6
what should I do?
I'm using postgresql.
thank you..
This is the query to get the output like you told but writing in the text file you need to work.
SELECT year,month,date, rain, tmax,timin
FROM yourTable WHERE Location='air' and id_stat='98212';