How do i plot temperature vs date and time?

조회 수: 9 (최근 30일)
Niclas Dahlman
Niclas Dahlman 2012년 11월 12일
Hey
I´m trying to plot data from a matrix looking like this: 3 columns with several measurements each day at different times.
Day Time Temp 1 09:00 16 2 09:00 16.2
and so on.
I want to create a plot with temp on y axis and day AND time on the x axis. So far i managed to plot the temp vs time, but this generates a graph with many different lines but not separated by day som they all end upon top of each other.
I need a command that makes matlab differentiate between the days, not only the time.
Ive been looking at commands like xtick, datetick etc but i dont get how to create what im looking for using these commands.
Thanks in advance for tips and hints.

답변 (2개)

Star Strider
Star Strider 2012년 11월 12일
The datenum function might be what you need.
  댓글 수: 1
Niclas Dahlman
Niclas Dahlman 2012년 11월 13일
Thanks for your reply Star Strider. Going to try this later today, one prolem I think of is the separation of date and time in two different columns. Can i somehow merge column 1 and 2 so datenum uses all the information at once, both date and time? Maybe there is an easier way to sort the data?

댓글을 달려면 로그인하십시오.


Andrei Bobrov
Andrei Bobrov 2012년 11월 13일
편집: Andrei Bobrov 2012년 11월 13일
file yourdata.txt have values:
Day Time Temp
1 09:00 16
2 09:00 16.2
...
solution
f = fopen('yourdata.txt');
c = textscan(f,'%f %s %f','HeaderLines',1);
fclose(f);
d = [c{1}-1 + rem(datenum(c{2},'HH:MM'),1), c{3}];

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by