dylanmikesell / GEOS397

Course material for GEOS397 (Fall 2016)
MIT License
3 stars 16 forks source link

Homework 8 Part 2.1 #12

Open alexedwards15 opened 8 years ago

alexedwards15 commented 8 years ago

The function that we used in order to create the time vector was datetime, using a the beginning month and year, stepping through each month, then ending with the final month and year.

We then plotted this result against the streamflow data that was given to us in a .txt format.

Because of the nature of the datetime function, this gave us a chronologically sorted vector. Therefore we did not see the necessity to use the sort function. Our graph follows the same trends, but is slightly different than the one in the assignment (slight right shift).

Is there really a necessity for the sort function, if the vector is already sorted? Or is there an error with the results of using the datetime function?

jbshuler commented 8 years ago

We ran into something very similar. The problem as I see it is this: our date vector is chronologically sorted but the data vector is not. Check the first line in Table 1. Note that that between elements 3 and 4, the data actually goes back in time from Dec. 1953 to Jan. 1953. Another way to confirm this would be to check the very first y-axis value in your plot. Ours was 2, but it should be 240 as Dylan's plot shows, since that corresponds to the first date we are given.

All that said, I have no clue how to fix it.

jbshuler commented 7 years ago

This is code is garbage but it worked to produce the datetime array in the form we needed it:

tEnd = datetime(1953, 9, 1) + calmonths(1:3); tBeg = datetime(1953, 0, 1) + calmonths(1:9); tfirst = [tEnd tBeg]; tfinal(1,:) = tfirst;

for i=1:17; tfinal(i+1,:) = tfirst + calyears(i); end

tfinal2 = tfinal'; tArray = (reshape(tfinal2,1,216))';

THEN sort tArray and use the sortIndex to sort the cavecreek data so that time-data pairs are maintained. Then you can plot and it matches the figure in the HW. This part of the doc helped:

[B,I] = sort(___) also returns a collection of index vectors for any of the previous syntaxes. I is the same size as A and describes the arrangement of the elements of A into B along the sorted dimension. For example, if A is a numeric vector, B = A(I).

alexedwards15 commented 7 years ago

Ah, I've been agonizing over this for a while now, I see it now! So you are creating two datetime arrays that you can piece together to form a water calendar year, then you fill the matrix with the 18 year span with the for loop. Then reshape puts it into the form we need in order to do the sort function with the data that we are given with the cavecreek.txt file.

That is EXTREMELY helpful, thank you so much for your help!