Azzera filtri
Azzera filtri

Cumulative sum by month

1 visualizzazione (ultimi 30 giorni)
Gareth Maver
Gareth Maver il 12 Feb 2016
Risposto: Star Strider il 12 Feb 2016
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.
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?

Risposte (1)

Star Strider
Star Strider il 12 Feb 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.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by