Clear Filters
Clear Filters

Contour Plot: DATA COLLECTED vs TIME in date and hours

3 views (last 30 days)
Hello, All. Thank you in advance for any help, contribution and your time. I have been asked to do a contour plot with a data vs time (date and hours), I am new with Matlab and I don't really know how to make this date and hour in a time series vector to do my contour plot. I have added the data and time for the plot, each time correspond to each data.
DATA & TIME: 09/23/2008 06:37:00 09/23/2008 06:46:00 09/23/2008 06:52:00 09/23/2008 07:00:00 09/23/2008 07:03:00 09/23/2008 07:10:00 09/23/2008 07:15:00 09/23/2008 07:15:00 09/23/2008 07:15:00 09/23/2008 07:22:00 09/23/2008 07:26:00 09/23/2008 07:30:00 09/23/2008 07:44:00 09/23/2008 07:48:00 09/23/2008 07:52:00 09/23/2008 07:52:00 09/23/2008 08:00:00 09/23/2008 08:07:00 09/23/2008 08:26:00 09/23/2008 08:26:00 09/23/2008 08:26:00 09/23/2008 08:26:00 09/23/2008 08:36:00 09/23/2008 08:45:00 09/23/2008 08:45:00 09/23/2008 09:03:00 09/23/2008 09:07:00 09/23/2008 09:10:00 09/23/2008 09:12:00 09/23/2008 09:45:00 09/23/2008 09:53:00 09/23/2008 09:56:00 09/23/2008 09:59:00 09/23/2008 10:15:00 09/23/2008 10:19:00 09/23/2008 10:23:00 09/23/2008 10:26:00 09/23/2008 10:46:00 09/23/2008 10:51:00 09/23/2008 11:03:00 09/23/2008 11:09:00 09/23/2008 11:30:00
DATA COLLECTED: 77.17391304 81.73076923 68.53002070 78.24609109 72.50000000 78.93617021 78.71602082 78.99437774 76.33373319 72.82282282 70.03222342 78.52906287 73.14662273 62.69315673 67.33668342 67.33668342 62.53902185 73.21178121 78.53315149 81.32196315 81.86759896 80.43368633 77.51329332 76.89075630 74.82312034 80.64516129 63.14136126 75.27512839 99.95674201 74.91749175 66.70201485 72.31578947 74.24857839 76.74008811 80.06872852 75.18910741 81.28031038 78.17543860 77.52403846 78.49017580 79.54122753 71.64461248

Accepted Answer

Rick Rosson
Rick Rosson on 5 Jul 2011
The first thing you might try is to read your date/time stamps into MATLAB as strings. One way to accomplish this outcome would be to place the date/time data into a plain text file, with one date/time stamp per line of text. Then save the file as data.txt or something similar.
You can then read the date/time stamps into MATLAB from the text file and convert the strings into an array of datenums.
txt = fopen('data.txt','r');
k = 0;
while ~feof(txt)
k = k + 1;
aStr = fgetl(txt);
dtStamp(k) = datenum(aStr);
end
fclose(txt);
Once you have the date/time stamps in datenum form, you can always retrieve the individual parts as follows:
yr = year(dtStamp(k));
mo = month(dtStamp(k));
dy = day(dtStamp(k));
etc.
That should get you started.
HTH.
Rick
  3 Comments
Rick Rosson
Rick Rosson on 5 Jul 2011
I am not sure what you are trying to show in the contour plot. Usually a contour plot represents the projection of a surface in 3D onto the 2D plane. In other words, if Z=f(X,Y), then I might create a contour plot showing the values of Z projected onto the XY-plane as contour lines. Is that what you are trying to do? What are your two independent variables X and Y? Which is the dependent variable Z?
Ruben Llamas
Ruben Llamas on 5 Jul 2011
Mr Rosson,
I don't know why all the values (1 x 42) of dtStamp matrix are the same= 7.336742756944444e+05, I think they must be different because they are different times of the same date.
Ruben

Sign in to comment.

More Answers (2)

Rick Rosson
Rick Rosson on 5 Jul 2011
Please try the following:
disp([hour(dtStamp') minute(dtStamp')]);
What does it show in the Command Window?
Rick
  2 Comments
Ruben Llamas
Ruben Llamas on 5 Jul 2011
this is what I got: ??? Undefined function or method 'hour' for input arguments of type 'double'.
Ruben Llamas
Ruben Llamas on 5 Jul 2011
I did run the code you advised me as follow:
txt = fopen('data923.txt','r');
k = 1;
while ~feof(txt)
aStr = fgetl(txt);
dtStamp(k) = datenum(aStr);
k = k + 1;
end
fclose(txt);
yr = year(dtStamp(k));
mo = month(dtStamp(k));
dy = day(dtStamp(k));

Sign in to comment.


Rick Rosson
Rick Rosson on 5 Jul 2011
Sorry, hour and minute are not included in base MATLAB (they are part of the Financial Toolbox).
Please try this instead:
disp(datevec(dtStamp'));
This will print out a table of all of the date/time stamps in the form of
YYYY MM DD hh mm ss
You should see that not each row shows different values, at least for the hours and minutes.
HTH.
  2 Comments
Ruben Llamas
Ruben Llamas on 5 Jul 2011
Hello, Mr Rosson
this is what I got:
disp(datevec(dtStamp'))
2008 9 23 6 37 0
2008 9 23 6 46 0
2008 9 23 6 52 0
2008 9 23 7 0 0
2008 9 23 7 3 0
2008 9 23 7 10 0
2008 9 23 7 15 0
2008 9 23 7 15 0
2008 9 23 7 15 0
2008 9 23 7 22 0
2008 9 23 7 26 0
2008 9 23 7 30 0
2008 9 23 7 44 0
2008 9 23 7 48 0
2008 9 23 7 52 0
2008 9 23 7 52 0
2008 9 23 8 0 0
2008 9 23 8 7 0
2008 9 23 8 26 0
2008 9 23 8 26 0
2008 9 23 8 26 0
2008 9 23 8 26 0
2008 9 23 8 36 0
2008 9 23 8 45 0
2008 9 23 8 45 0
2008 9 23 9 3 0
2008 9 23 9 7 0
2008 9 23 9 10 0
2008 9 23 9 12 0
2008 9 23 9 45 0
2008 9 23 9 53 0
2008 9 23 9 56 0
2008 9 23 9 59 0
2008 9 23 10 15 0
2008 9 23 10 19 0
2008 9 23 10 23 0
2008 9 23 10 26 0
2008 9 23 10 46 0
2008 9 23 10 51 0
2008 9 23 11 3 0
2008 9 23 11 9 0
2008 9 23 11 30 0
this looks really nice! Thanks!
Then, now, I need to plot "datevec" vs "collect data" to get a contour plot??
Thanks,
Ruben LL
Ruben Llamas
Ruben Llamas on 5 Jul 2011
Mr Rick Rosson,
Thank you very much!!!
I got my contour plot already,
Can I have your email to ask you similar things in the future?
You have been really helpful! thank you for your patience.
Have a great day,
Ruben Llamas

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!