How to combine correlated year, month and day vectors

17 ビュー (過去 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 Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by