{"id":445,"date":"2016-03-14T10:18:26","date_gmt":"2016-03-14T14:18:26","guid":{"rendered":"https:\/\/blogs.mathworks.com\/graphics\/?p=445"},"modified":"2016-03-14T10:18:26","modified_gmt":"2016-03-14T14:18:26","slug":"as-the-wind-blows","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/graphics\/2016\/03\/14\/as-the-wind-blows\/","title":{"rendered":"As the Wind Blows"},"content":{"rendered":"<div class=\"content\"><h3>As the Wind Blows<\/h3><p>NOAA maintains a number of buoys that collect weather data, and they publish the data from them on <a href=\"http:\/\/www.ndbc.noaa.gov\/\">their website<\/a>.<\/p><p>There are four of these buoys just outside Boston harbor. They are the red squares on this map.<\/p><p>\r\n<a href=\"http:\/\/www.ndbc.noaa.gov\/?lat=41.500000&lon=-70.100000&zoom=6&type=oceans&status=r&pgm=&op=&ls=n\">\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_map.png\" alt=\"\">\r\n<\/a>\r\n<\/p><p>For example, the data for buoy 44013, which is the bottom one on that map, is available <a href=\"http:\/\/www.ndbc.noaa.gov\/station_history.php?station=44013\">at this URL<\/a>.<\/p><p>I downloaded the data for 2015, and I can read it into MATLAB like this:<\/p><pre class=\"codeinput\">t=readtable(<span class=\"string\">'44013c2015.txt'<\/span>,<span class=\"string\">'Format'<\/span>,<span class=\"string\">'%d%d%d%d%f%f%f%f%f%f'<\/span>,<span class=\"string\">'HeaderLines'<\/span>,2);\r\nt.Properties.VariableNames = {<span class=\"string\">'YY'<\/span>,<span class=\"string\">'MM'<\/span>,<span class=\"string\">'DD'<\/span>,<span class=\"string\">'hh'<\/span>,<span class=\"string\">'mm'<\/span>,<span class=\"string\">'WDIR'<\/span>,<span class=\"string\">'WSPD'<\/span>,<span class=\"string\">'GDR'<\/span>,<span class=\"string\">'GST'<\/span>,<span class=\"string\">'GTIME'<\/span>};\r\n<\/pre><p>We can see that there are 52,460 rows in this table. That's one measurement every ten minutes for the entire year.<\/p><pre class=\"codeinput\">size(t)\r\nt(3805:3810,:)\r\n<\/pre><pre class=\"codeoutput\">ans =\r\n       52460          10\r\nans = \r\n     YY     MM    DD    hh    mm    WDIR    WSPD    GDR    GST     GTIME\r\n    ____    __    __    __    __    ____    ____    ___    ____    _____\r\n    2015    1     27    9      0    19      20.7    999      99    9999 \r\n    2015    1     27    9     10    17      22.3    999      99    9999 \r\n    2015    1     27    9     20    18      21.6    999      99    9999 \r\n    2015    1     27    9     30    17      21.5    999      99    9999 \r\n    2015    1     27    9     40    14      20.9    999      99    9999 \r\n    2015    1     27    9     50    13      21.1     16    28.8     946 \r\n<\/pre><p>I'm going to convert the date information into datetime to make it easier to work with.<\/p><pre class=\"codeinput\">timestamp = datetime(t.YY,t.MM,t.DD,t.hh,t.mm,0);\r\n<\/pre><p>Now I can plot the wind direction and speed using the new <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/polarplot.html\">polarplot<\/a> command that was just introduced in R2016a. Note that polarplot wants angles in radians, but we have degrees. That means that we'll want to use the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/deg2rad.html\">deg2rad function<\/a>.<\/p><pre class=\"codeinput\">h = polarplot(deg2rad(t.WDIR),t.WSPD);\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_01.png\" alt=\"\"> <p>This looks a lot like the old <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/polar.html\">polar function<\/a> that has been in MATLAB for years, but there are some important differences. It created a line object, but if you look closely you can see that it's not quite like the line object you're used to. Notice that instead of XData and YData properties, it has properties named ThetaData and RData. When you use the older polar function, if you want to get the data from the line object, you need to convert it back to theta and r yourself by calling <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/cart2pol.html\">cart2pol<\/a>. With polarplot, the line object takes care of that for you.<\/p><pre class=\"codeinput\">h\r\n<\/pre><pre class=\"codeoutput\">h = \r\n  Line with properties:\r\n\r\n              Color: [0 0.4470 0.7410]\r\n          LineStyle: '-'\r\n          LineWidth: 0.5000\r\n             Marker: 'none'\r\n         MarkerSize: 6\r\n    MarkerFaceColor: 'none'\r\n          ThetaData: [1x52460 double]\r\n              RData: [1x52460 double]\r\n              ZData: [1x0 double]\r\n\r\n  Use GET to show all properties\r\n<\/pre><p>And take a look at the axes it created.<\/p><pre class=\"codeinput\">ax = gca\r\n<\/pre><pre class=\"codeoutput\">ax = \r\n  PolarAxes with properties:\r\n\r\n             ThetaLim: [0 360]\r\n                 RLim: [0 25]\r\n       ThetaAxisUnits: 'degrees'\r\n             ThetaDir: 'counterclockwise'\r\n    ThetaZeroLocation: 'right'\r\n\r\n  Use GET to show all properties\r\n<\/pre><p>This is a new PolarAxes, and it has a bunch of properties which are useful here. For example, since the wind direction is in compass points, I want 0 to be north, the values to proceed in a clockwise direction, and the values displayed in degrees. I can do that by just setting these 3 properties.<\/p><pre class=\"codeinput\">ax.ThetaAxisUnits = <span class=\"string\">'degrees'<\/span>;\r\nax.ThetaZeroLocation = <span class=\"string\">'top'<\/span>;\r\nax.ThetaDir = <span class=\"string\">'clockwise'<\/span>;\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_02.png\" alt=\"\"> <p>We can even switch over to compass points if we'd like:<\/p><pre class=\"codeinput\">ax.ThetaTick=0:45:360;\r\nax.ThetaTickLabels={<span class=\"string\">'N'<\/span>,<span class=\"string\">'NE'<\/span>,<span class=\"string\">'E'<\/span>,<span class=\"string\">'SE'<\/span>,<span class=\"string\">'S'<\/span>,<span class=\"string\">'SW'<\/span>,<span class=\"string\">'W'<\/span>,<span class=\"string\">'NW'<\/span>,<span class=\"string\">'N'<\/span>};\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_03.png\" alt=\"\"> <pre class=\"codeinput\">ax.ThetaTick=0:22.5:360;\r\nax.ThetaTickLabels={<span class=\"string\">'N'<\/span>,<span class=\"string\">'NNE'<\/span>,<span class=\"string\">'NE'<\/span>,<span class=\"string\">'ENE'<\/span>,<span class=\"string\">'E'<\/span>,<span class=\"string\">'ESE'<\/span>,<span class=\"string\">'SE'<\/span>,<span class=\"string\">'SSE'<\/span>,<span class=\"string\">'S'<\/span>,<span class=\"string\">'SSW'<\/span>,<span class=\"string\">'SW'<\/span>,<span class=\"string\">'WSW'<\/span>,<span class=\"string\">'W'<\/span>,<span class=\"string\">'WNW'<\/span>,<span class=\"string\">'NW'<\/span>,<span class=\"string\">'NNW'<\/span>,<span class=\"string\">'N'<\/span>};\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_04.png\" alt=\"\"> <p>And I can customize the ThetaAxis or RAxis, just the way I'm used to customizing the XAxis or YAxis on a \"regular\" Axes object.<\/p><pre class=\"codeinput\">ax.RAxisLocation = 90;\r\nax.RAxis.Color = [1\/2 1\/2 1\/2];\r\nax.RAxis.Label.String = <span class=\"string\">'Wind Speed'<\/span>;\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_05.png\" alt=\"\"> <p>But that plot is really not very useful, is it? What if we looked at just one day? I'm going to pick January 27th, because we had a really big storm that day.<\/p><pre class=\"codeinput\">mask = timestamp&gt;=datetime(2015,1,27) &amp; timestamp&lt;datetime(2015,1,28);\r\nh.ThetaData = deg2rad(t.WDIR(mask));\r\nh.RData = t.WSPD(mask);\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_06.png\" alt=\"\"> <p>You can see we had 20 knot winds coming out of the northeast. We call that type of storm a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Nor%27easter\">nor'easter<\/a> in Boston, and they're usually the dangerous ones. This one dropped 22 inches of snow on us.<\/p><pre class=\"codeinput\">text(3*pi\/16,21,<span class=\"string\">'Nor''easter'<\/span>,<span class=\"string\">'FontSize'<\/span>,10,<span class=\"string\">'FontWeight'<\/span>,<span class=\"string\">'bold'<\/span>,<span class=\"string\">'Color'<\/span>,[3\/8 3\/8 3\/8])\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_07.png\" alt=\"\"> <p>That was the start of a really awful stretch of record breaking snow last winter. Here's what the next couple of weeks looked like.<\/p><pre class=\"codeinput\">hold <span class=\"string\">on<\/span>\r\n<span class=\"keyword\">for<\/span> d=datetime(2015,1,28)+days(1:13)\r\n    mask = timestamp&gt;=d &amp; timestamp&lt;(d+days(1));\r\n    polarplot(deg2rad(t.WDIR(mask)),t.WSPD(mask));\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_08.png\" alt=\"\"> <p>Now I'd like to animate the plot and see the entire year. I could just set the ThetaData and RData in a loop, but I'd like my animation to look a bit smoother.<\/p><p>To make the animation look smooth, I'm going to draw 6 days at a time, and fade the older days out. I can do the fade by creating 6 line objects.<\/p><pre class=\"codeinput\">cla\r\nm = <span class=\"string\">'o'<\/span>;\r\nth = 0:pi\/4:2*pi;\r\nr = ones(size(th));\r\nh = [polarplot(th,r  ,m), polarplot(th,r+1,m), polarplot(th,r+2,m), <span class=\"keyword\">...<\/span>\r\n     polarplot(th,r+3,m), polarplot(th,r+4,m), polarplot(th,r+5,m)];\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_09.png\" alt=\"\"> <p>Now I'll set the colors so they fade between white for my oldest data and blue for my newest.<\/p><pre class=\"codeinput\"><span class=\"keyword\">for<\/span> i=1:6\r\n    s = (i-1)\/5;\r\n    set(h(i),<span class=\"string\">'Color'<\/span>,hsv2rgb(.5661,s,1));\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_10.png\" alt=\"\"> <p>And I'll lock the RLim, so the plot doesn't bounce around during the animation.<\/p><pre class=\"codeinput\">ax.RLim = [0, max(t.WSPD)];\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/buoy_example_11.png\" alt=\"\"> <p>Now I'm ready to animate.<\/p><p>For each day, I copy to data from each line object to the next older one, and then add the data for the new day.<\/p><pre class=\"codeinput\"><span class=\"keyword\">for<\/span> d=datetime(2015,1,1):datetime(2015,12,31)\r\n    <span class=\"comment\">% Roll the old data down the line<\/span>\r\n    <span class=\"keyword\">for<\/span> i=1:5\r\n        h(i).ThetaData = h(i+1).ThetaData;\r\n        h(i).RData = h(i+1).RData;\r\n    <span class=\"keyword\">end<\/span>\r\n    <span class=\"comment\">% Add the current day's data<\/span>\r\n    mask = timestamp&gt;=d &amp; timestamp&lt;(d+days(1));\r\n    h(end).ThetaData = deg2rad(t.WDIR(mask));\r\n    h(end).RData = t.WSPD(mask);\r\n    <span class=\"comment\">% Update the title<\/span>\r\n    title(datestr(d))\r\n    <span class=\"comment\">% Tell the graphics system to draw<\/span>\r\n    drawnow\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/graphics\/2016\/wind_direction_animation.gif\" alt=\"\"><p>I've been enjoying the new polarplot function, but I should mention that not all of the graphics commands work with <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/polaraxes.html\">PolarAxes<\/a> yet. You're basically limited to lines and text for the moment. If you need to put other things in your polar plots, the existing <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/polar.html\">polar<\/a>, <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/pol2cart.html\">pol2cart<\/a>, and <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/cart2pol.html\">cart2pol<\/a> functions will be sticking around, so you can continue to do things the old way.<\/p><p>And speaking of <a href=\"https:\/\/www.mathworks.com\/products\/matlab\/whatsnew.html\">cool new features in R2016a<\/a>, be sure to check out the new <a href=\"https:\/\/www.mathworks.com\/products\/matlab\/live-editor\/\">Live Editor<\/a>. I've uploaded some of my favorite blog posts to the File Exchange as Live Scripts. <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=authorid%3A336426+tag%3A%22live+script%22\">Here's a link<\/a> so you can download them and try them out.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_5e564a3a590747fa9e728913b2918867() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='5e564a3a590747fa9e728913b2918867 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 5e564a3a590747fa9e728913b2918867';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2016 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_5e564a3a590747fa9e728913b2918867()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2016a<br><\/p><\/div><!--\r\n5e564a3a590747fa9e728913b2918867 ##### SOURCE BEGIN #####\r\n%% As the Wind Blows\r\n% NOAA maintains a number of buoys that collect weather data, and they\r\n% publish the data from them on <http:\/\/www.ndbc.noaa.gov\/ their website>.\r\n%\r\n% There are four of these buoys just outside Boston harbor. They are the \r\n% red squares on this map.\r\n%\r\n% <html>\r\n% <a href=\"http:\/\/www.ndbc.noaa.gov\/?lat=41.500000&lon=-70.100000&zoom=6&type=oceans&status=r&pgm=&op=&ls=n\">\r\n% <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"..\/buoy_map.png\" alt=\"\"> \r\n% <\/a>\r\n% <\/html>\r\n%\r\n% For example, the data for buoy 44013, which is the bottom\r\n% one on that map, is available\r\n% <http:\/\/www.ndbc.noaa.gov\/station_history.php?station=44013 at this URL>.\r\n%\r\n% I downloaded the data for 2015, and I can read it into MATLAB like this:\r\n%\r\nt=readtable('44013c2015.txt','Format','%d%d%d%d%f%f%f%f%f%f','HeaderLines',2);\r\nt.Properties.VariableNames = {'YY','MM','DD','hh','mm','WDIR','WSPD','GDR','GST','GTIME'};\r\n\r\n%%\r\n% We can see that there are 52,460 rows in this table. That's one\r\n% measurement every ten minutes for the entire year.\r\n%\r\nsize(t)\r\nt(3805:3810,:)\r\n\r\n%%\r\n% I'm going to convert the date information into datetime to make it easier\r\n% to work with.\r\n%\r\ntimestamp = datetime(t.YY,t.MM,t.DD,t.hh,t.mm,0);\r\n\r\n%%\r\n% Now I can plot the wind direction and speed using the new \r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/polarplot.html polarplot>\r\n% command that was just introduced in R2016a. Note that polarplot wants\r\n% angles in radians, but we have degrees. That means that we'll want to use\r\n% the <https:\/\/www.mathworks.com\/help\/matlab\/ref\/deg2rad.html deg2rad\r\n% function>.\r\n%\r\nh = polarplot(deg2rad(t.WDIR),t.WSPD);\r\n\r\n%%\r\n% This looks a lot like the old\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/polar.html polar function> that\r\n% has been in MATLAB for years, but there are some important differences.\r\n% It created a line object, but if you look closely you can see that it's\r\n% not quite like the line object you're used to.\r\n% Notice that instead of XData and YData properties, it has\r\n% properties named ThetaData and RData. When you use the older polar\r\n% function, if you want to get the data from the line object, you need to\r\n% convert it back to theta and r yourself by calling <https:\/\/www.mathworks.com\/help\/matlab\/ref\/cart2pol.html cart2pol>.\r\n% With polarplot, the line object takes care of that for you.\r\n% \r\nh\r\n\r\n%%\r\n% And take a look at the axes it created.\r\n%\r\nax = gca\r\n\r\n%%\r\n% This is a new PolarAxes, and it has a bunch of properties which are\r\n% useful here. For example, since the wind direction is in compass points,\r\n% I want 0 to be north, the values to proceed in a clockwise direction, and\r\n% the values displayed in degrees. I can do that by just setting these 3\r\n% properties.\r\n%\r\nax.ThetaAxisUnits = 'degrees';\r\nax.ThetaZeroLocation = 'top';\r\nax.ThetaDir = 'clockwise';\r\n\r\n%%\r\n% We can even switch over to compass points if we'd like:\r\n%\r\nax.ThetaTick=0:45:360;\r\nax.ThetaTickLabels={'N','NE','E','SE','S','SW','W','NW','N'};\r\n\r\n%%\r\nax.ThetaTick=0:22.5:360;\r\nax.ThetaTickLabels={'N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','N'};\r\n\r\n%%\r\n% And I can customize the ThetaAxis or RAxis, just the way I'm used to customizing the\r\n% XAxis or YAxis on a \"regular\" Axes object.\r\n%\r\nax.RAxisLocation = 90;\r\nax.RAxis.Color = [1\/2 1\/2 1\/2];\r\nax.RAxis.Label.String = 'Wind Speed';\r\n\r\n%%\r\n% But that plot is really not very useful, is it? What if we looked at just \r\n% one day? I'm going to pick January 27th, because we had a really big \r\n% storm that day.\r\n%\r\nmask = timestamp>=datetime(2015,1,27) & timestamp<datetime(2015,1,28);\r\nh.ThetaData = deg2rad(t.WDIR(mask));\r\nh.RData = t.WSPD(mask);\r\n\r\n%%\r\n% You can see we had 20 knot winds coming out of the northeast. We call\r\n% that type of storm a <https:\/\/en.wikipedia.org\/wiki\/Nor%27easter nor'easter> in Boston, and they're usually the\r\n% dangerous ones. This one dropped 22 inches of snow on us.\r\n%\r\ntext(3*pi\/16,21,'Nor''easter','FontSize',10,'FontWeight','bold','Color',[3\/8 3\/8 3\/8])\r\n%%\r\n% That was the start of a really awful stretch of record breaking snow last \r\n% winter. Here's what the next couple of weeks looked like.\r\n%\r\nhold on\r\nfor d=datetime(2015,1,28)+days(1:13)\r\n    mask = timestamp>=d & timestamp<(d+days(1));\r\n    polarplot(deg2rad(t.WDIR(mask)),t.WSPD(mask));\r\nend\r\n%%\r\n% Now I'd like to animate the plot and see the entire year. I could just set the\r\n% ThetaData and RData in a loop, but I'd like my animation to look a bit\r\n% smoother. \r\n%\r\n% To make the animation look smooth, I'm going to draw 6 days at a time, and fade the\r\n% older days out. I can do the fade by creating 6 line objects.\r\n%\r\ncla\r\nm = 'o';\r\nth = 0:pi\/4:2*pi;\r\nr = ones(size(th));\r\nh = [polarplot(th,r  ,m), polarplot(th,r+1,m), polarplot(th,r+2,m), ...\r\n     polarplot(th,r+3,m), polarplot(th,r+4,m), polarplot(th,r+5,m)];\r\n\r\n%%\r\n% Now I'll set the colors so they fade between white for my oldest data and\r\n% blue for my newest.\r\n%\r\nfor i=1:6\r\n    s = (i-1)\/5;\r\n    set(h(i),'Color',hsv2rgb(.5661,s,1));\r\nend\r\n\r\n%%\r\n% And I'll lock the RLim, so the plot doesn't bounce around during the\r\n% animation.\r\n%\r\nax.RLim = [0, max(t.WSPD)];\r\n\r\n%%\r\n% Now I'm ready to animate.\r\n%\r\n% For each day, I copy to data from each line object to the next older one,\r\n% and then add the data for the new day.\r\n%\r\nfor d=datetime(2015,1,1):datetime(2015,12,31)    \r\n    % Roll the old data down the line\r\n    for i=1:5\r\n        h(i).ThetaData = h(i+1).ThetaData;\r\n        h(i).RData = h(i+1).RData;\r\n    end\r\n    % Add the current day's data\r\n    mask = timestamp>=d & timestamp<(d+days(1));\r\n    h(end).ThetaData = deg2rad(t.WDIR(mask));\r\n    h(end).RData = t.WSPD(mask);\r\n    % Update the title\r\n    title(datestr(d))\r\n    % Tell the graphics system to draw\r\n    drawnow\r\nend\r\n\r\n%%\r\n%\r\n% <<..\/wind_direction_animation.gif>>\r\n%\r\n\r\n%%\r\n% I've been enjoying the new polarplot function, but I should mention that\r\n% not all of the graphics commands work with <https:\/\/www.mathworks.com\/help\/matlab\/ref\/polaraxes.html PolarAxes> yet. \r\n% You're basically limited to lines and text for the moment. If you need to\r\n% put other things in your polar plots, the existing \r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/polar.html polar>, \r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/pol2cart.html pol2cart>, and \r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/cart2pol.html cart2pol>\r\n% functions will be sticking around, so you can continue to do things the old way.\r\n\r\n%%\r\n% And speaking of <https:\/\/www.mathworks.com\/products\/matlab\/whatsnew.html cool new features in R2016a>, be sure to check out the new \r\n% <https:\/\/www.mathworks.com\/products\/matlab\/live-editor\/ Live Editor>. I've\r\n% uploaded some of my favorite blog posts to the File Exchange as Live\r\n% Scripts. \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=authorid%3A336426+tag%3A%22live+script%22\r\n% Here's a link> so you can download them and try them out.\r\n%\r\n\r\n##### SOURCE END ##### 5e564a3a590747fa9e728913b2918867\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/graphics\/files\/feature_image\/buoy_example_thumbnail.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>As the Wind BlowsNOAA maintains a number of buoys that collect weather data, and they publish the data from them on their website.There are four of these buoys just outside Boston harbor. They are... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/graphics\/2016\/03\/14\/as-the-wind-blows\/\">read more >><\/a><\/p>","protected":false},"author":89,"featured_media":447,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/posts\/445"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/users\/89"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/comments?post=445"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/posts\/445\/revisions"}],"predecessor-version":[{"id":446,"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/posts\/445\/revisions\/446"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/media\/447"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/media?parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/categories?post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics\/wp-json\/wp\/v2\/tags?post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}