How to combine correlated year, month and day vectors
15 views (last 30 days)
Show older comments
chloe Izarr-Barton
on 30 Mar 2020
Commented: chloe Izarr-Barton
on 18 Apr 2020
Hi,
I have a data set i want to plot against time but the year, month and day that correlate to my measurements are all seperate parameters in the workspace. When i try plotting them it will plot three seperate data points instead of one point for one date.
I am new to Matlab so sorry if i am asking a simple question. Any help would be much appreciated.
Thanks
%load vectors%
load GLODAPv2.2019_Atlantic_Ocean.mat
%load area%
LA=G2latitude;
LO=G2longitude;
papbox=find(LO>0 & LO<50 & LA>0 & LA <60);
%load dates%
Y=G2year;
M=G2month;
D=G2day;
%load BGC parameters%
sal=G2salinity;
%extract site area for all used vectors including BGC and time%
salp=sal(papbox);
Ypap=Y(papbox);
Mpap=M(papbox);
Dpap=D(papbox);
%combining date vectors%
d1=datenum('01-01-2010','dd-mm-yyyy');
d2=datenum('31-12-2016','dd-mm-yyyy');
d=datevec(d1:d2);
d=d(:,1:3);
%plot figures%
figure(1);plot(d,salp,'x');
0 Comments
Accepted Answer
Steven Lord
on 30 Mar 2020
Use your Y, M, and D vectors to build a datetime array and pass that datetime array into plot. Here's a small example:
Y = 2020;
M = 3;
D = 1:30;
T = datetime(Y, M, D)
sampleY = D.^2;
plot(T, sampleY)
More Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!