how to plot two figures in one figure with different axes

I am trying to plot flows collected in different time of the day for different days in the same plot. As the moments of collection are not exactly the same for each day the second plot is drawn in the continues of the first one:
whle I need them something like this:

2 Comments

And what are your inputs? If you post the relevant part of the code, we can suggest a modification. But without seeing the code, the readers have to invent it.
this is part of data for two different days:
d1.PNG
and
d2.PNG
and I use this script to import data:
filename = 'Rtest.xlsx';
sheet = '3';
xlRange = 'B2:E1441';
data1 = xlsread(filename, sheet,xlRange);
year1 = 2018;
month1 = 05;
day1 = 20;
hour1 = data1(:,1);
min1 = data1(:,2);
sec1 = data1(:,3);
flow1 = data1(:,4);
date1 = datenum(year1, month1, day1,hour1, min1,sec1);
and the same for the second day, and use the following script to plot them in one figure:
figure(1);
plot(date1,flow1);
datetick('x',15)
hold on
plot(date2,flow2);
datetick('x',15)
while the result is the plot of second data appears as continue of the first one as the x axis data are not exactly the same.
Thanks for your time.

Sign in to comment.

 Accepted Answer

Simply replace the line:
date2 = datenum(year2, month2, day2, hour2, min2, sec2);
by
date2 = datenum(year1, month1, day1, hour2, min2, sec2);
Then the data will use the same day.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!