Cumulative sum by month
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Basically I am wanting to recreate this figure but with the cumulative sum plotted at monthly intervals - i.e. more line detail is wanted in between the year ticks.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154870/image.png)
I have this code which creates the above figure:
long = data(:,1) ;
lati = data(:,2) ;
year = data(:,3) ;
month = data(:,4) ; % year and month are in numerical form - e.g. 1985 01
mag = data(:,6) ;
for i = 1:length(mag)
if mag(i) < 3
mag(i) = NaN ;
lati(i) = NaN ;
long(i) = NaN ;
year(i) = NaN ;
month(i) = NaN ;
end
end
cum_year = [1985:1:2015] ;
n = zeros(length(cum_year),1) ;
cum_year = cum_year' ;
for j = 1:length(n)
for i = 1:length(mag) ;
if year(i) == cum_year(j)
n(j) = n(j)+1 ;
end
end
end
year_sum = zeros(length(n),1) ;
for i = 1:length(n) ;
year_sum(i) = sum(n(1:i)) ;
end
figure ;
plot(cum_year(1:24),year_sum(1:24),'b','LineWidth',1.5) ;
hold on
plot(cum_year(24:29),year_sum(24:29),'Color',[0.0 0.8 0.3],'LineWidth',1.5) ;
plot(cum_year(29:31),year_sum(29:31),'r','LineWidth',1.5) ;
So is there anyway of a cumulative sum on a monthly basis, where the year is changing?
1 commentaire
Réponses (1)
Star Strider
le 12 Fév 2016
I don’t entirely understand what you want. I would simply replace the stairs call (in my previous code) with a plot call to get a continuous line:
plot(PlotMtx(:,1), PlotMtx(:,2), '-g', 'LineWidth',2)
It would be possible to write code to reproduce your plot if I had all the data that created it.
0 commentaires
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!