You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How can I plot hourly data in the same figure?
3 views (last 30 days)
Show older comments
My data as follows:
- 1st column: Year
- 2nd column: Day of the year
- 3st column: Hour
- 6st column: Value
I'd like to do statistic analysis such as median, minimum, maximum, and mean for every season and then plot in the same figure. Problem is that hour column is not at regular intervals for me. That's why output figure is not what I want.
2 Comments
Suat YAZICI
on 5 Apr 2019
Hour value is irregular. It changes its interval in related to years. For example, interval hour of 1st winter season is between 1 and 23 by increasing 2 but my code plots 0 value and there is no 0 value in this data.
I would like to do hourly variaton according to winter season in this data by calculating statistic analysis and then plotting it in the same figure according to its own hour values.
Accepted Answer
dpb
on 5 Apr 2019
Edited: dpb
on 5 Apr 2019
Use the features of Matlab to your advantage...granted, it takes some "time in grade!" to learn one's way around! :)
As a general rule, when one finds that are building specific indices into the data, that's a real sign there should be a better way...in this case, converting to datetime in order to do the comparisons is the trick. And, it turns out your Q? immediately follows essentially the same problem in financial analysis and is quite common also with such data as yours...the same 'trick" as used there (link) works very well here as well--
load winter.txt
w=table(datetime(winter(:,1),1,winter(:,2),winter(:,3),0,0),winter(:,6) ...
'VariableNames',{'Date','Data'}); % create table from array
w.WYear=fix((w.Date-w.Date(1))./duration(24*365+isleapyr(w.Date),0,0)); % compute the winter year
yr=unique(year(w.Date)); % retrieve the years covered
yrlabel=cellstr(num2str([yr mod(round(100*(yr/100-fix(yr/100)))+1,100)],'%d-%02d')); % build a label array
labels={'Winter','Mean','Median','Minimum','Maximum','StdDev','LowLimit','UpLimit'}; % output statistics
g=findgroups(w.WYear); % grouping variable by winter
[av,md,mn,mx,sd,lo,hi]=splitapply(@multipleStatistics,w.Data,g); % compute statistics
summ=table(categorical(yrlabel),av,md,mn,mx,sd,lo,hi,'VariableNames',labels); % build a summary table
>> summ =
summ =
20×8 table
Winter Mean Median Minimum Maximum StdDev LowLimit UpLimit
_______ ______ ______ _______ _______ ______ ________ _______
1998-99 17.909 14.9 4.1 51 10.114 4.3556 31.462
1999-00 21.358 18 3.4 63.2 13.36 3.4553 39.26
2000-01 22.821 19.75 5.3 60.7 13.627 4.5608 41.082
2001-02 38.467 34.45 5.3 92.5 20.885 10.481 66.453
2002-03 20.464 16.1 3.8 60.6 11.386 5.2074 35.721
2003-04 14.101 11.3 3.9 45.2 7.4069 4.1757 24.026
2004-05 11.731 10.1 0.2 31.2 5.4401 4.4414 19.021
2005-06 10.189 9.4 3.3 25.6 3.3511 5.6982 14.679
2006-07 9.063 8.1 0.7 19.8 3.1426 4.8519 13.274
2007-08 8.5001 8 3.2 22.2 2.6795 4.9095 12.091
2008-09 8.7789 8.6 2.8 17.9 2.3483 5.6322 11.926
2009-10 9.8379 9.5 2.8 25 3.2059 5.542 14.134
2010-11 10.533 10.05 3.5 35.4 3.7726 5.4773 15.588
2011-12 15.377 13.55 3.3 41.7 6.7471 6.3357 24.418
2012-13 13.316 11.5 3.2 41.1 5.8716 5.4482 21.184
2013-14 18.659 16.3 4 60.8 9.9698 5.2995 32.019
2014-15 20.451 17.1 5.1 50.9 10.52 6.3538 34.548
2015-16 12.464 10.7 3.3 34.8 5.6957 4.8319 20.096
2016-17 9.2583 8.5 3.6 23.9 3.185 4.9904 13.526
2017-18 8.8444 8.5 4.1 17 2.4073 5.6186 12.07
>>
23 Comments
dpb
on 5 Apr 2019
Since above is already somewhat long, in case it's not obvious how to add the second categorization by hour...we're already almost there--
[g,ig1,ig2]=findgroups(w.WYear,hour(w.Date)); % add second grouping variable of hour
[av,md,mn,mx,sd,lo,hi]=splitapply(@multipleStatistics,w.Data,g); % recompute statistics w/ new grouping
hrsumm=table(categorical(yrlabel(ig1+1)),ig2,av,md,mn,mx,sd,lo,hi, ... % build new hourly summary table
'VariableNames',[labels(1) 'Hour' labels(2:end)]);
>> hrsumm(1:20,:)
ans =
20×9 table
Winter Hour Mean Median Minimum Maximum StdDev LowLimit UpLimit
_______ ____ ______ ______ _______ _______ ______ ________ _______
1998-99 1 10.31 10.05 6 16.6 2.1129 7.4787 13.141
1998-99 3 9.03 8.95 5.1 12.6 1.6205 6.8585 11.202
1998-99 5 9.0178 9.05 6.1 12.7 1.4399 7.0883 10.947
1998-99 7 8.4111 8.2 4.2 11.7 1.4586 6.4566 10.366
1998-99 9 7.5011 7.45 4.1 10.9 1.3901 5.6384 9.3638
1998-99 11 18.506 17.6 13.6 26 3.2883 14.099 22.912
1998-99 13 26.564 26.5 17.2 40.1 4.8266 20.097 33.032
1998-99 15 31.679 31.4 20 51 5.906 23.765 39.593
1998-99 17 32.511 32.65 21.5 46 5.84 24.685 40.337
1998-99 19 29.127 28.8 18.9 40 5.2808 22.05 36.203
1998-99 21 19.59 18.35 12.7 30.6 4.7764 13.19 25.99
1998-99 23 12.658 11.6 6.8 23.2 3.5926 7.8437 17.472
1999-00 1 12.21 11 6.1 30.6 4.4259 6.2791 18.141
1999-00 3 10.425 9.6 5.3 21.2 3.1412 6.2161 14.634
1999-00 5 9.6066 9.1 5.1 17 2.4163 6.3688 12.844
1999-00 7 8.0033 7.7 3.4 14.4 2.0015 5.3213 10.685
1999-00 9 6.6604 6.5 3.7 11.5 1.6418 4.4604 8.8605
1999-00 11 20.949 20.8 14 32.9 4.2855 15.207 26.692
1999-00 13 31.459 30.8 19.6 56 7.2983 21.68 41.239
1999-00 15 37.724 36.1 24.6 58.3 8.3597 26.522 48.926
>>
To plot each group by hour, simply iterate through the table selecting each value of the Winter variable in turn and plot against Hour
You can set the x-axis limits and ticks however want; by default Matlab selects "pretty" limits and tick values which why the zero shows up even though the hours are always starting at 1:00
Suat YAZICI
on 5 Apr 2019
I try understading your code step by step.
w.WYear=fix((w.Date-w.Date(1))./duration(24*365+isleapyr(w.Date),0,0)); % compute the winter year
What is "isleapyr"? It is neither variable nor function, isn't it?
dpb
on 5 Apr 2019
Edited: dpb
on 6 Apr 2019
It's my function referenced in the previous answer I linked to above that returns T|F (0|1) depending on whether the year is leap year or not. I intended to point that out above and forgot...
function is=isleapyr(yr)
% returns T for input year being a leapyear
if isdatetime(yr), yr=year(yr); end
is=eomday(yr,2)==29;
Suat YAZICI
on 5 Apr 2019
Edited: Suat YAZICI
on 5 Apr 2019
I got an error as follow:
" Error using splitapply (line 132)
Applying the function 'multipleStatistics' to the 1st group of data generated the following error:
Undefined function 'multipleStatistics' for input arguments of type 'double'. "
Should I use multipleStatistics.m file like this and x means w.Data,g ?
function [av,md,mn,mx,sd,lo,hi] = multipleStatistics(x)
av = mean(x);
md = median(x);
mn = min(x);
mx = max(x);
sd = std(x);
lo = mean(x)-1.34*std(x);
hi = mean(x)+1.34*std(x);
end
dpb
on 6 Apr 2019
Yes...I woulda' swore I had attached the code for it but I don't see the link...don't know what happened...that one works; mine looked just a tiny bit different in that I factored out the Z -- which reminds me that I was going to ask why that particular value? It doesn't match up with any common percentile of the standard normal...
>> normcdf(1.34)
ans =
0.9099
>> norminv(0.91)
ans =
1.3408
>> norminv(0.90)
ans =
1.2816
>>
Nothing really seemed obvious as to the value...I did factor it out so could change it in the code in one spot.
Suat YAZICI
on 6 Apr 2019
Edited: Suat YAZICI
on 6 Apr 2019
I tried to calculate values for first year and I got some result like yours but I don't understand that why my calculate is different from output. Did I miss something?
Output:
Winter Hour Mean Median Minimum Maximum StdDev LowLimit UpLimit
1998-99 1 10.31 10.05 6 16.6 2.1129 7.4787 13.141
My calculate:
Winter Hour Mean Median Minimum Maximum StdDev LowLimit UpLimit
1998-99 1 10.13 9.80 6 17.5 2.18 7.21 13.05
dpb
on 6 Apr 2019
Edited: dpb
on 6 Apr 2019
Different data file, maybe? be one guess. W/o the exact code you ran couldn't really say anything else...just a couple different values or few more or less entries in the file could easily make that size of differences...
Just to make sure the timing logic is working correctly, I did the following here:
ibrk=find([0;diff(w.WYear)]); % find where the year indicator changes
for i=1:numel(ibrk),w(ibrk(i)-1:ibrk(i),:),end % show the record before, too...
ans =
2×6 table
Year Day Hour Data Date WYear
____ ___ ____ ____ ____________________ _____
1999 59 23 22.3 28-Feb-1999 23:00:00 0
1999 335 1 9.2 01-Dec-1999 01:00:00 1
ans =
2×6 table
Year Day Hour Data Date WYear
____ ___ ____ ____ ____________________ _____
2000 60 23 35.6 29-Feb-2000 23:00:00 1
2000 336 1 8.8 01-Dec-2000 01:00:00 2
ans =
2×6 table
Year Day Hour Data Date WYear
____ ___ ____ ____ ____________________ _____
2001 59 23 26.7 28-Feb-2001 23:00:00 2
2001 335 1 16.2 01-Dec-2001 01:00:00 3
ans =
2×6 table
Year Day Hour Data Date WYear
____ ___ ____ ____ ____________________ _____
2002 59 23 58.9 28-Feb-2002 23:00:00 3
2002 335 0 7 01-Dec-2002 00:00:00 4
...
ans =
2×6 table
Year Day Hour Data Date WYear
____ ___ ____ ____ ____________________ _____
2016 60 23 12 29-Feb-2016 23:00:00 17
2016 336 0 9.3 01-Dec-2016 00:00:00 18
ans =
2×6 table
Year Day Hour Data Date WYear
____ ___ ____ ____ ____________________ _____
2017 59 23 9 28-Feb-2017 23:00:00 18
2017 335 0 7.8 01-Dec-2017 00:00:00 19
>>
That shows the year marker does break every year at end of February including the leap year year. Hence, I think the results I got should be correct.
You did use the isleapyr() function, right? Not using it would ignore the leap year and make a little different year division.
dpb
on 6 Apr 2019
Edited: dpb
on 6 Apr 2019
Oh, another possibility in another file...the duration() logic to set the year breakpoint does rely on the first data record in the file be the first time period in the year. If you had a file that didn't begin on 1DecYYYY 01:00:00, then every year would end up beginning at that time.
If that is possible, augment the input data file with a record that has that beginning date/time value for the year,day,hour fields and then compute the year indicator variable.
Having done that, you can then delete the reference record from the dataset before continuing to findgroups and splitapply
Suat YAZICI
on 6 Apr 2019
Same file...Yes, I used isleapyr() function. I did crosscheck that my output is correct.
Mean formula as follow:
Parameters are:
, 6st column of winter.txt for raw data or 2st column of w variable in your code;
μ, mean.
The sum of the mean differences have to be zero.
According to my calculate, and
According to code output, and
In addition to that, max value is 17.5, not 16.6.
Check please 1117st row(December 4, 1999) of w variation. Its values is 17.5 and it is max value.
I am so confused.
dpb
on 6 Apr 2019
Edited: dpb
on 6 Apr 2019
Dec 4, 1999 is in winter of 1999-2000, not winter 1998-99. 1998-99 is Dec98-Feb99. It is very easy to get mixed up in keeping straight, though...
Look at what
> tg1=w(find(g==1),:);
>> mean(tg1.Data)
ans =
10.3100
>>
returns and you can actually look at the data returned for each group by, for example--
w(find(g==1),:)
ans =
90×6 table
Year Day Hour Data Date WYear
____ ___ ____ ____ ____________________ _____
1998 335 1 14.1 01-Dec-1998 01:00:00 0
1998 336 1 11.9 02-Dec-1998 01:00:00 0
1998 337 1 11.8 03-Dec-1998 01:00:00 0
1998 338 1 10.7 04-Dec-1998 01:00:00 0
1998 339 1 11.1 05-Dec-1998 01:00:00 0
1998 340 1 9.5 06-Dec-1998 01:00:00 0
...
and see every line pulled. I don't see any missed nor any extra for the hour 01:00:00 and the month between Dec, 1998 thru the subsequent Feb, 1999. Looks to me like your test code is getting the December of the year+1 rolled into the previous winter, too (or maybe is doing Jan,Feb,Dec of the same year which would be a pretty easy logic error to make).
Let's see...
>> ix99_1=(w.Year==1999 & ismember(month(w.Date),[1:2 12]) & w.Hour==1);
>> sum(ix99_1)
ans =
90
>> mean(w.Data(ix99_1))
ans =
10.1911
>> max(w.Data(ix99_1))
ans =
17.5000
>>
That gets almost the same mean and does return the 17.5 as the max. Something like the above must be what your code calculated altho I can't tell just precisely what, again, without the actual code itself..
If you're using the original sample code with hardcocded record numbers, I'd guess one or more of those has an "off by one" error.
dpb
on 6 Apr 2019
>> tg13=w(find(g==13),:);
>> tg13(1:10,:)
ans =
10×6 table
Year Day Hour Data Date WYear
____ ___ ____ ____ ____________________ _____
1999 335 1 9.2 01-Dec-1999 01:00:00 1
1999 336 1 12.4 02-Dec-1999 01:00:00 1
1999 337 1 14 03-Dec-1999 01:00:00 1
1999 338 1 17.5 04-Dec-1999 01:00:00 1
1999 339 1 11.3 05-Dec-1999 01:00:00 1
1999 340 1 8.4 06-Dec-1999 01:00:00 1
1999 341 1 7.2 07-Dec-1999 01:00:00 1
1999 342 1 6.1 08-Dec-1999 01:00:00 1
1999 343 1 7.5 09-Dec-1999 01:00:00 1
1999 344 1 7.3 10-Dec-1999 01:00:00 1
...
which shows that the subject record is included in that second year as should be...it doesn't show up as the maximum for that year/hour, however, as there are several other readings greater than 17.5...
>> sum(tg13.Data>17.5)
ans =
11
>> max(tg13.Data)
ans =
30.6000
>>
Would have to see the actual code you used in your calculations to see where it went wrong, but everything I can see indicates to me the above results are correct for the problem described.
Now, if you change the definition of the winter season, all bets are off! :)
Suat YAZICI
on 6 Apr 2019
Edited: Suat YAZICI
on 6 Apr 2019
I see my fault right now. I am so sorry for wasting your time.
I have last question. Data for 2017 year begins with 355 and ends with 365. So, there is no pass to next year. It confused me.
Thank you for all effort.
dpb
on 6 Apr 2019
That's true--I hadn't done any checking for whether each season was a full complement of three months or not...so the last "seasonal year" data reported is, in fact, just the one month of Dec17, yes.
You could check this in a number of ways to eliminate the data from the table for incomplete seasons.
Not to worry...happy to try to ensure that things are working correctly...I'm still learning how to use splitapply myself so practice is always beneficial! :)
Hopefully this gets you along towards your goals...
Out of curiosity, what are the actual measurements and where are the observations from?
Suat YAZICI
on 6 Apr 2019
Edited: Suat YAZICI
on 7 Apr 2019
TEC is defined by the integral of electron denstiy in a 1 column along the signal tranmission path. Unit is .
Every measurement is vertical total electron content value as a grid and I extracted data via C#. The Total Electron Content(TEC) is one of important parameters in the Earth's ionosphere, related to various space weather and solar activities. It can be derived from dual-frequency Global Navigation Satelllite System(GNSS) carrier phase and code observations.
Beside the point, I applied your code for spring season and it is just for one year whether leap year or not but I am not sure that output is correct. I didn't edit yrlabel like one year. Can you check it?
load spring.txt
w=table(datetime(spring(:,1),1,spring(:,2),spring(:,3),0,0),spring(:,6),'VariableNames',{'Date','Data'});
w.WYear=fix((w.Date-w.Date(1))./duration(24*365+isleapyr(w.Date),0,0));
yr=unique(year(w.Date));
yrlabel=cellstr(num2str([yr mod(round(100*(yr/100-fix(yr/100))),100)],'%d-%02d'));
labels={'Spring','Mean','Median','Minimum','Maximum','StdDev','LowLimit','UpLimit'};
[g,ig1,ig2]=findgroups(w.WYear,hour(w.Date));
[av,md,mn,mx,sd,lo,hi]=splitapply(@multipleStatistics,w.Data,g);
hrsumm=table(categorical(yrlabel(ig1+1)),ig2,av,md,mn,mx,sd,lo,hi, 'VariableNames',[labels(1) 'Hour' labels(2:end)]);
dpb
on 7 Apr 2019
Edited: dpb
on 7 Apr 2019
Kewl! I presume you have one of the readers working to pull the data from the raw files; it wouldn't take too much to build one w/ Matlab, but no need to reinvent the wheel...
I haven't tested the other seasons dates against the time logic but the idea should be invariant to the actual season; it's based on the time since the first record in the file compared to the length of years since; just that it starts counting from the beginning date in the file to compute which year each measurement is in. That does mean that it takes splitting the data in the input file to contain the desired months only instead of splitting out seasons from a file that contained a full year of data. That would take some different logic.
You can check your results by the example tests I showed earlier of selecting given subsets of the grouping variable and looking at the results to be sure.
I would suggest making one change in that logic, however...I noticed later that there are some days with data collection on even hours in the day instead of odd and the logic uses the exact datetime number of the first entry for the beginning of the year. Using hour zero instead would be slightly more robust in the reference time...I think I showed that in one of the comments earlier...but I don't see that I actually did post the actual code--
% compute seasonal year from initial file day, but time 00:00:00 in the file
w.WYear=fix((w.Date-datetime(w.Year(1),1,w.Day(1),0,0,0))./duration(24*365+isleapyr(w.Date),0,0));
This begins with the first day in the file--in reality if there were missing data that would also redefine the beginning of a year. This was built for the reference starting at the arbitrary date first given in the data file; the code could be made more general by making that reference date an external input independent of the file.
Suat YAZICI
on 7 Apr 2019
Edited: Suat YAZICI
on 7 Apr 2019
Unrecognized variable name 'Year'.
% compute seasonal year from initial file day, but time 00:00:00 in the file
w.WYear=fix((w.Date-datetime(w.Year(1),1,w.Day(1),0,0,0))./duration(24*365+isleapyr(w.Date),0,0));
I think it is ok your first code. I tested it. I tried to say that yrlabels and labels of variables.
yrlabel=cellstr(num2str([yr mod(round(100*(yr/100-fix(yr/100))),100)],'%d-%02d'));
labels={'Spring','Mean','Median','Minimum','Maximum','StdDev','LowLimit','UpLimit'};
Spring output such as 1999-1999 because of format ('%d-%02d'). It doesn't write correctly if I edit format like '%d'. For example, Spring output should be only 1999, not 1999-1999.
dpb
on 7 Apr 2019
Edited: dpb
on 7 Apr 2019
Oh...I forgot. I had earlier changed the way I built w here because the first variable really isn't the Date but the Year so I renamed it to be more accurate. I never did change anything I posted back here, though, to reflect that. Sorry...
w=array2table([winter(:,1:3) winter(:,6)],'VariableNames',{'Year','Day','Hour','Data'});
w.WYear=fix((w.Date-datetime(w.Year(1),1,w.Day(1),0,0,0))./duration(24*365+isleapyr(w.Date),0,0));
>> w(1,:)
ans =
1×6 table
Year Day Hour Data Date WYear
____ ___ ____ ____ ____________________ _____
1998 335 1 14.1 01-Dec-1998 01:00:00 0
is what I ended up with for the table -- if you don't create the Year variable, then the Date field will end up being overwritten. That's ok, by then to get the Year one has to apply the year() function to the Date variable if need it, so I figured just keep it even though is a little redundancy. Your choice which way you want to go in the end...
I dic notice it seemed like rounding worked OK, with either 00:00:00 or 01:00:00 as the start time but strictly speaking, the 00:00:00 is correct for a calendar season beginning coinciding to the first of a month and it is rounding that is making it work. It is more robust to use the actual time even if "can get away with" not.
On the labels, you'll need to fixup the arguments to num2str to only use the year value without the second calculated value, yes. Take the pieces out to the command line to see what it is actually doing inside the [] and you should be able to follow what you need to change...a learning exercise! :)
Suat YAZICI
on 7 Apr 2019
Edited: Suat YAZICI
on 7 Apr 2019
I see variable names, respectively, year, day, hour but w.WYear variable includes w.Date which is unreorganized variable. I don't understand how you get result. Because I got error again :)
Beside, I attached spring.txt. Please check hrsumm output. First column('Spring') 1999-99; ...; 2000-00 and so on. Why doesn't it look like just 1999;...; 2000 and so on?
load spring.txt
w=table(datetime(spring(:,1),1,spring(:,2),spring(:,3),0,0),spring(:,6),'VariableNames',{'Date','Data'});
w.WYear=fix((w.Date-w.Date(1))./duration(24*365+isleapyr(w.Date),0,0));
yr=unique(year(w.Date));
yrlabel=cellstr(num2str([yr mod(round(100*(yr/100-fix(yr/100))),100)],'%d-%02d'));
labels={'Spring','Mean','Median','Minimum','Maximum','StdDev','LowLimit','UpLimit'};
[g,ig1,ig2]=findgroups(w.WYear,hour(w.Date));
[av,md,mn,mx,sd,lo,hi]=splitapply(@multipleStatistics,w.Data,g);
hrsumm=table(categorical(yrlabel(ig1+1)),ig2,av,md,mn,mx,sd,lo,hi, 'VariableNames',[labels(1) 'Hour' labels(2:end)]);
Variation of yrlablel problem?
dpb
on 7 Apr 2019
Edited: dpb
on 7 Apr 2019
w=table(datetime(spring(:,1),1,spring(:,2),spring(:,3),0,0),spring(:,6), ...
'VariableNames',{'Date','Data'});
w.WYear=fix((w.Date-w.Date(1))./duration(24*365+isleapyr(w.Date),0,0));
Yes, that's going back to the very firstest case...you'll note that isn't the same definition for the table w as in the last comment nor the same as in my second Answer that showed the hourly groupings. That one doesn't keep the Year, Day, Hour data that I decided was probably "agoodthing" to keep around -- if you do go that way, then .
w.WYear=fix((w.Date-datetime(year(w.Date(1)),month(w.Date(1)),day(w.Date(1)))) ...
./duration(24*365+isleapyr(w.Date),0,0));
just seemed like a lot of extra work in having to wrap the Date variable inside the year and day functions to retrieve data already had. Plus, NB: that to do it that way have to also get the month because now day() isn't the day of year but day of month so that would compute the wrong indexing vector entirely. (I did make one simplification of using the three-argument form instead of the six since the time components are all now zero).
Then, in
yr=unique(year(w.Date));
yrlabel=cellstr(num2str([yr mod(round(100*(yr/100-fix(yr/100))),100)],'%d-%02d'));
you still haven't fixed the arguments to num2str to only use one year value. Have you done as I suggested and taken
num2str([yr mod(round(100*(yr/100-fix(yr/100))),100)],'%d-%02d'))
out to the command line and figured out what it's doing yet? Start with that for a given value for yr and then dig into the pieces of the expression until you understand what each is doing and then it will become obvious what needs to be modified.
Suat YAZICI
on 7 Apr 2019
Edited: dpb
on 7 Apr 2019
Frankly, I understand your code expect [except is the word looking for there....and I know English isn't your first language and you do very well so that isn't criticism but instruction -- expect is to anticipate something. dpb] yrlabel part but I thought I didn't express myself very well.
I applied your first code, which is winter.txt, for spring.txt. It is for winter as follow:
yrlabel=cellstr(num2str([yr mod(round(100*(yr/100-fix(yr/100)))+1,100)],'%d-%02d')); % build a label array
part of "...fix(yr/100)))+1 & '%d-%02d' ''for building {Year} such as 1998-1999, right?
There is no problem if I remove +1 inside your code and apply it for spring but I didn't edit for format becasue output is 1999-99. 4 digit year for output enough in my view.
Spring Hour Mean Median Minimum Maximum StdDev LowLimit UpLimit
_______ ____ ______ ______ _______ _______ _______ ________ _______
1999-99 1 19.055 18.15 6.9 32.4 5.6933 11.426 26.684
1999-99 3 16.617 15.4 7.7 27.7 5.4098 9.3682 23.867
...
1999-99 21 32.721 33.1 19.6 42.7 5.9953 24.687 40.754
1999-99 23 25.312 24.4 12.1 38.2 6.5444 16.542 34.081
2000-00 1 31.868 31.3 21.5 48.4 4.9698 25.209 38.528
2000-00 3 29.15 28.9 17.1 45.2 4.7684 22.76 35.54
2000-00 5 24.666 24.55 14.5 39.8 4.2049 19.032 30.301
...
dpb
on 7 Apr 2019
Edited: dpb
on 7 Apr 2019
That's one way to solve the appearance issue, yes, but... I was trying to coax you to figure out what is actually going on inside the square brackets as a teaching opportunity... so you'd have another piece of Matlab syntax/idiomatic usage in your toolbox going forward. :)
Follow along the following sequence of operations at the command line -- something along these lines is what I was suggesting you do to understand...
>> yr=1999;
>> yrlabel=cellstr(num2str([yr mod(round(100*(yr/100-fix(yr/100)))+1,100)],'%d-%02d'))
>> (num2str([yr mod(round(100*(yr/100-fix(yr/100)))+1,100)],'%d-%02d'))
>> [yr mod(round(100*(yr/100-fix(yr/100)))+1,100)]
>> [yr]
>> [mod(round(100*(yr/100-fix(yr/100)))+1,100)]
>> (round(100*(yr/100-fix(yr/100)))+1)
>> (yr/100-fix(yr/100))
>> (num2str([yr],'%d'))
>> yrlabel=cellstr(num2str(yr,'%d'))
>> yr=unique(year(w.Date(1)));
>> yrlabel=cellstr(num2str(yr,'%d'))
that progressively goes into the innards piecewise to tear it down to its component parts, then gradually builds it back up again with the desired result instead...this is a key technique in picking up other peoples' code to figure out what it is doing when not completely apparent. With, of course diligent study of the documentation of any functions used like mod and num2str here.
More Answers (0)
See Also
Categories
Find more on Calendar in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)