How to combine correlated year, month and day vectors

13 visualizaciones (últimos 30 días)
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');

Respuesta aceptada

Steven Lord
Steven Lord el 30 de Mzo. de 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)

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by