To label each curve with its corresponding year in your MATLAB plot, you can use the text function to place annotations directly on the graph. Since the years are not consecutive, you will need to specify them manually. Here's how you can modify your code to include year labels for each curve:
% Define the years corresponding to your data
years = [2001, 2003, 2005, 2007, 2009, 2011, 2013, 2015]; % Example years
% Ensure the length of 'years' matches 'Cyears'
if length(years) ~= Cyears
error('The length of the years array must match the number of years (Cyears).');
end
% Plot the long-term CDF
figure(3)
plot(xcdf, CDFmed_lt, '*-b'); hold on; % Long-term CDF
for n = 1:Cyears
% Plot each short-term CDF
plot(xcdf, CDFmed_st(:,n), '.-r');
% Add text label to each curve
% Find the position where to place the label
y_pos = CDFmed_st(end, n); % Position at the end of the curve
text(xcdf(end), y_pos, sprintf('%d', years(n)), 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'right');
end
% Plot the long-term CDF again for clarity in the legend
plot(xcdf, CDFmed_lt, '*-b'); hold off;
title('CDFs Radiación Abril');
legend('Largo Plazo', 'Corto Plazo');
xlabel('Radiación Global (MJ/m^2)');
ylabel('CDF');
% rest of the code...
For more details, please refer to the following MathWorks documentation: https://www.mathworks.com/help/matlab/ref/text.html
Hope this helps!