Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Plotting line graph - ignoring missing dates (YYYY, MM, DD, HH:MM)

Status
Not open for further replies.

RE776

Specifier/Regulator
Feb 17, 2011
16
0
0
GB
Hi,

I have a large set of senor data collected every minute for 102 days.
In which, 1st columen contains dates in the format of YYYY,MM,DD,HH:MM. And 2nd column contains values, whole number from (8 - 20)

My problem is that the sensor wasn't 100% reliable hence there were some gaps scattered through column 1 and 2. These gaps were deleted when downloading the data from the sensor, Hence it looks something like this

09/11/2013 18:38
09/11/2013 18:39
09/11/2013 18:40
09/11/2013 18:41
09/11/2013 18:42
09/11/2013 18:43
11/11/2013 7:29
11/11/2013 7:30
11/11/2013 7:31
11/11/2013 7:32
11/11/2013 7:33
11/11/2013 7:34


In column 2, I have some data which despite have a date in the first column the value is shown as zero, which is basically a value when the sensor just started up. I have replaced these zero as NaN.

I intention is to plot a graph that will ignore the missing dates and just joint the last and first values of the data together, e.g. from above, data point 09/11/2013 18:43 will join to 11/11/2013 7:29, and the x-axis will not show all the minutes between the missing gap.

If some can give me a hand that would be much appreciated.

Many Thank

John
 
Replies continue below

Recommended for you

?? Seems to work fine for me. Are you sure you're using the scatter plot and not the line plot?

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529
 
I tried to use plot and scatter, but I still get the a big gap, for my particular case, the bigest gap I have is about 16 days, my senors take samples every minute. I am relatively new to matlab, and I have a feeling I am missing something fundamental here.
 
My data looks something like this below:

Dates Data 1 Data 2
09/11/2013 18:38 20 19
09/11/2013 18:39 19 NaN
09/11/2013 18:40 NaN 11
09/11/2013 18:41 4 8
09/11/2013 18:42 18 2
09/11/2013 18:43 4 11
11/11/2013 7:29 NaN 15
11/11/2013 7:30 2 10
11/11/2013 7:31 11 14
11/11/2013 7:32 14 NaN
11/11/2013 7:33 NaN 20
11/11/2013 7:34 NaN 18



And my m code is something like below, can anyone tell me what the gap is still be ploted out?

Many Thanks

function plotParticleSensorsALL(X1, YMatrix1, YMatrix2, YMatrix3, Start_date, Finish_date)

% X1: vector of x data
% YMATRIX1: 2 sets
% YMATRIX2: 2 sets
% YMATRIX3: 2 sets
% Start_date: first date of the data record
% Finish_date: Last date of the data record



% Create figure
figure1 = figure('Position', [209, 249, 1400, 750]);
%----------------------------------------------------------------------------------------------------
% Creating 4um graph
% Create axes
axes1 = axes('Parent',figure1,...
'XLim',[Start_date Finish_date],...
'Position',[0.16 0.710521421117724 0.805714285714286 0.211850457988714]);

%% Uncomment the following line to preserve the X-limits of the axes

box(axes1,'on');
hold(axes1,'all');
datetick('x','dd/mm/yyyy HH:MM','keepticks')

% Create multiple lines using matrix input to plot
plot1 = plot(X1,YMatrix1,'Parent',axes1,'MarkerFaceColor',[0 0 0],...
'LineWidth',2);
set(plot1(1),'DisplayName','A (Main)');
set(plot1(2),'DisplayName','B (Pilot)');


% Create xlabel
xlabel('Time','FontSize',12);

% Create ylabel
ylabel('m','FontSize',12);

% Create title
title('1st graph','FontSize',14);

%--------------------------------------------------------------------------------------------------------
% Creating 2nd graph
% Create axes
axes2 = axes('Parent',figure1,...
'XLim',[Start_date Finish_date],...
'Position',[0.16 0.397007907604211 0.805714285714285 0.211850457988714]);



%% Uncomment the following line to preserve the X-limits of the axes

box(axes2,'on');
hold(axes2,'all');
datetick('x','dd/mm/yyyy HH:MM','keepticks')

% Create multiple lines using matrix input to plot
plot2 = plot(X1,YMatrix2,'Parent',axes2,'MarkerFaceColor',[0 0 0],...
'LineWidth',2);
set(plot2(1),'DisplayName','A (Main)');
set(plot2(2),'DisplayName','B (Pilot)');

% Create xlabel
xlabel('Time','FontSize',12);

% Create ylabel
ylabel('m','FontSize',12);

% Create title
title('2nd graph','FontSize',14);
%----------------------------------------------------------------------------------------------------
% Creating 3rd graph
% Create axes
axes3 = axes('Parent',figure1,...
'XLim',[Start_date Finish_date],...
'Position',[0.16 0.0537646643609681 0.805714285714285 0.211850457988714]);


%% Uncomment the following line to preserve the X-limits of the axes

box(axes3,'on');
hold(axes3,'all');
datetick('x','dd/mm/yyyy HH:MM','keepticks')

% Create multiple lines using matrix input to plot
plot3 = plot(X1,YMatrix3,'Parent',axes3,'MarkerFaceColor',[0 0 0],...
'LineWidth',2);
set(plot3(1),'DisplayName','A (Main)');
set(plot3(2),'DisplayName','B (Pilot)');

% Create xlabel
xlabel('Time','FontSize',12);

% Create ylabel
ylabel('PPM','FontSize',12);

% Create title
title('3rd graph','FontSize',14);

%----------------------------------------------------------------------------------------------------

% Create legend
legend1 = legend(axes1,'show');
set(legend1,...
'Position',[0.0068918583500594 0.432503118133938 0.110947042348466 0.159788166544924]);

 
Status
Not open for further replies.
Back
Top