How to combine correlated year, month and day vectors

조회 수: 15 (최근 30일)
chloe Izarr-Barton
chloe Izarr-Barton 2020년 3월 30일
댓글: chloe Izarr-Barton 2020년 4월 18일
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');

채택된 답변

Steven Lord
Steven Lord 2020년 3월 30일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by