0
votes

enter image description hereHere I have two data sets with time series. I want plot that two data set in one figure by using matlab and I tried to plot it and it's coming as an error. Could you please help me to solve this problem? Here I upload the code:

x={'6:15','9:25 ','11:00 ','13:50 ','16:25','19:00 ','20:00 ','22:05 ','23:40 '}; %time
y=[141 95 149 85 135 63 111 115 287]                % values
time_out=datenum(x,'HH:MM');  %convert time to datenum
figure
plot(time_out,y,'.-')            
datetick('x','HH:MM')
hold on
x4={'6:58','9:50 ','11:45 ','13:40','15:45','17:40 ','18:35 ','22:15 ','00:08 '}; %time
y4=[116 118 252 142 159 185 162 130 204]                % values
out4=datenum(x4,'HH:MM');  %convert time to datenum
figure
plot(out4,y4,'.-')            
datetick('x4','HH:MM')

and my graph is not proper also.

2
the last line datetick('x4','HH:MM') -> datetick('x','HH:MM')Anthony
Thank you for the response and I tried it and two graphs came in one figure.But my second graph is not proper . Because my time is early morning 12.08 value is going to other corner. Here I attach the image link...([1]: i.stack.imgur.com/8TTuC.png) I need that last time value into other side of the figure. Can you give me any suggestion to solve this problem?user8557031
Just move the last value in x4 and y4 to the beginning of the array.Anthony

2 Answers

0
votes

Just avoid the extra figure command.

figure
plot(time_out,y,'.-')            
datetick('x','HH:MM')
hold on
x4={'6:58','9:50 ','11:45 ','13:40','15:45','17:40 ','18:35 ','22:15 ','00:08 '}; %time
y4=[116 118 252 142 159 185 162 130 204]                % values
out4=datenum(x4,'HH:MM');  %convert time to datenum
plot(out4,y4,'.-')            
datetick('x4','HH:MM')
0
votes

Either just remove the second figure, or provide an explicit figure id. I prefer the latter, to prevent a larger amount of windows popping up:

x={'01:6:15','01:9:25 ','01:11:00 ','01:13:50 ','01:16:25','01:19:00 ','01:20:00 ','01:22:05 ','01:23:40'}; %time
y=[141 95 149 85 135 63 111 115 287];                % values
time_out=datenum(x,'dd:HH:MM');  %convert time to datenum
figure(1); clf; hold on;
plot(time_out,y,'.-')            

x4={'01:6:58','01:9:50 ','01:11:45 ','01:13:40','01:15:45','01:17:40','01:18:35','01:22:15','02:00:08'}; %time
y4=[116 118 252 142 159 185 162 130 204];                % values
out4=datenum(x4,'dd:HH:MM');  %convert time to datenum
figure(1); %just in case you created a second figure somewhere inbetween
plot(out4,y4,'.-')            
datetick('x','HH:MM')