Plot several seasonal NDVI time series data with marked transplanting time

3 views (last 30 days)
Dear all,
I have a time series NDVI data from 2014 to 2021 observed from October to March of next year as attached in the excel file. I want to plot 8 subplots vertically stacked corresponding to 8 years and for each year the transplating time will be highlighted with colors. There are two transplanting period for each year which were shown in the excel file. The idea is illustrated as the picture I modified by Paint. Please help me with this.

Answers (1)

Star Strider
Star Strider on 11 Mar 2023
I am not certain what you want to do with these data. I have no idea what ‘NDIV’ refers to.
This creates patch objects beginning with the date before each non-NaN value in ‘NDIV’ and extending to the next date in the series. I am guessing as to what you want, so you may need to change this to get the result you want, however it should get you started.
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1321105/Whole_periodNDVI_smo.xlsx', 'VariableNamingRule','preserve')
T1 = 54×3 table
Time series NDIV Smoothed ___________ _____ ________ 02-Sep-2014 NaN 0.632 02-Sep-2014 0.518 NaN 07-Sep-2014 NaN 0.549 12-Sep-2014 NaN 0.472 17-Sep-2014 NaN 0.405 18-Sep-2014 0.452 NaN 22-Sep-2014 NaN 0.347 27-Sep-2014 NaN 0.301 02-Oct-2014 NaN 0.265 04-Oct-2014 0.195 NaN 07-Oct-2014 NaN 0.238 12-Oct-2014 NaN 0.219 17-Oct-2014 NaN 0.207 20-Oct-2014 0.165 NaN 22-Oct-2014 NaN 0.202 27-Oct-2014 NaN 0.201
[G,ID] = findgroups(year(T1.('Time series')));
for k = 1:numel(ID)
Yrs{k,:} = T1(k==G,:);
end
figure
for k = 1:numel(Yrs)
% Yrs{k}
subplot(2,1,k)
v = find(~isnan(Yrs{k}.NDIV));
for k1 = 1:numel(v)
vidx = v(k1)+[-1;1];
xp = [Yrs{k}(vidx,:).('Time series'); flip(Yrs{k}(vidx,:).('Time series'))];
yp = reshape([ylim;ylim], [], 1);
hph = patch(xp, yp, 'r', 'DisplayName','NDIV', 'EdgeColor','r');
end
hold on
hpp = plot(Yrs{k}.('Time series'), Yrs{k}.Smoothed, 'DisplayName','Smoothed');
hold off
legend([hph(1),hpp], 'Location','bestoutside')
end
.

Community Treasure Hunt

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

Start Hunting!