필터 지우기
필터 지우기

Cumulative sum by month

조회 수: 1 (최근 30일)
Gareth Maver
Gareth Maver 2016년 2월 12일
답변: Star Strider 2016년 2월 12일
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?

답변 (1개)

Star Strider
Star Strider 2016년 2월 12일
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.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by