I draw a curve between two vector of points, not a function, how can I get the x-value of a certain y-value of the curve?
MATLAB: Get the x-value of a point on curve
interpolationplot
Related Solutions
Serial date numbers are, as their name implies, just numbers. So it is very easy to use logical comparisons, just like you would for comparing any other numbers.
First we generate some fake data (because you did not provide any):
>> N = 23;>> D = linspace(datenum(2019,5,29),datenum(2019,7,31),N);>> M = [D(:),randi(99,N,8)]M = 737574.00000 63.00000 70.00000 22.00000 74.00000 1.00000 27.00000 91.00000 91.00000 737576.86364 74.00000 36.00000 6.00000 57.00000 28.00000 43.00000 41.00000 72.00000 737579.72727 7.00000 99.00000 22.00000 56.00000 18.00000 95.00000 67.00000 79.00000 737582.59091 70.00000 68.00000 33.00000 73.00000 93.00000 87.00000 99.00000 44.00000 737585.45455 78.00000 57.00000 99.00000 21.00000 42.00000 27.00000 13.00000 22.00000 737588.31818 19.00000 95.00000 79.00000 4.00000 43.00000 67.00000 15.00000 10.00000 737591.18182 70.00000 33.00000 75.00000 67.00000 97.00000 46.00000 64.00000 89.00000 737594.04545 42.00000 48.00000 14.00000 18.00000 61.00000 65.00000 26.00000 48.00000 737596.90909 62.00000 7.00000 68.00000 18.00000 6.00000 76.00000 72.00000 90.00000 737599.77273 39.00000 77.00000 59.00000 79.00000 83.00000 77.00000 98.00000 48.00000 737602.63636 90.00000 93.00000 84.00000 4.00000 84.00000 66.00000 42.00000 21.00000 737605.50000 74.00000 13.00000 66.00000 12.00000 1.00000 74.00000 64.00000 48.00000 737608.36364 15.00000 20.00000 34.00000 71.00000 4.00000 1.00000 25.00000 54.00000 737611.22727 45.00000 65.00000 83.00000 26.00000 19.00000 47.00000 5.00000 53.00000 737614.09091 15.00000 25.00000 9.00000 94.00000 68.00000 45.00000 57.00000 52.00000 737616.95455 50.00000 84.00000 52.00000 47.00000 52.00000 82.00000 55.00000 16.00000 737619.81818 85.00000 33.00000 39.00000 97.00000 70.00000 41.00000 65.00000 41.00000 737622.68182 44.00000 88.00000 7.00000 16.00000 7.00000 47.00000 7.00000 8.00000 737625.54545 33.00000 33.00000 44.00000 60.00000 79.00000 60.00000 17.00000 58.00000 737628.40909 21.00000 29.00000 78.00000 63.00000 5.00000 69.00000 49.00000 68.00000 737631.27273 37.00000 43.00000 53.00000 72.00000 68.00000 33.00000 27.00000 39.00000 737634.13636 58.00000 56.00000 96.00000 27.00000 61.00000 89.00000 33.00000 56.00000 737637.00000 85.00000 58.00000 32.00000 22.00000 99.00000 91.00000 16.00000 80.00000
Then we can use basic MATLAB indexing to select only June's data:
>> idb = M(:,1) >= datenum(2019,6,1); % start of June
>> ide = M(:,1) < datenum(2019,7,1); % start of July
>> out = M(idb&ide,:)out = 737579.72727 7.00000 99.00000 22.00000 56.00000 18.00000 95.00000 67.00000 79.00000 737582.59091 70.00000 68.00000 33.00000 73.00000 93.00000 87.00000 99.00000 44.00000 737585.45455 78.00000 57.00000 99.00000 21.00000 42.00000 27.00000 13.00000 22.00000 737588.31818 19.00000 95.00000 79.00000 4.00000 43.00000 67.00000 15.00000 10.00000 737591.18182 70.00000 33.00000 75.00000 67.00000 97.00000 46.00000 64.00000 89.00000 737594.04545 42.00000 48.00000 14.00000 18.00000 61.00000 65.00000 26.00000 48.00000 737596.90909 62.00000 7.00000 68.00000 18.00000 6.00000 76.00000 72.00000 90.00000 737599.77273 39.00000 77.00000 59.00000 79.00000 83.00000 77.00000 98.00000 48.00000 737602.63636 90.00000 93.00000 84.00000 4.00000 84.00000 66.00000 42.00000 21.00000 737605.50000 74.00000 13.00000 66.00000 12.00000 1.00000 74.00000 64.00000 48.00000
And checking the first column to see that it only contains dates from June:
>> datestr(out(:,1))ans =03-Jun-2019 17:27:1606-Jun-2019 14:10:5409-Jun-2019 10:54:3212-Jun-2019 07:38:1015-Jun-2019 04:21:4918-Jun-2019 01:05:2720-Jun-2019 21:49:0523-Jun-2019 18:32:4326-Jun-2019 15:16:2129-Jun-2019 12:00:00
P = sortrows(P,7) ;
Most of the time functions don't operate "externally", so SORTROWS doesn't alter your array P defined in the workspace. It creates a new sorted array that it outputs. You have to store this output back into P if you want P to be the sorted version. If you wanted to keep the original, you could store it into a new variable:
P_sorted = sortrows(P,7) ;
Best Answer