# Plot for Number of Followers and Mentions for MATLAB on Twitter

## This plot is broken.

```Error using dateformverify (line 18)
DATESTR failed converting date number to date vector.  Date number out of range.

Error in datestr (line 195)
S = dateformverify(dtnumber, dateformstr, islocal);```
• Created by: Toshiaki Takeuchi

### Toshiaki Takeuchi (view profile)

• Latest result: Error using dateformverify (line 18) DATESTR failed converting date number to date vector. Date number out of range. Error in datestr (line 195) S = dateformverify(dtnumber, dateformstr, islocal);
• Created on: 04 Feb 2012
• Liked: 3 times

Count the number of followers and mentions for MATLAB on Twitter.

This trend uses the code from the Number of Followers for Matthew Simoneau (matthewsim) on Twitter trend.

```% Count the number of followers and mentions for MATLAB on Twitter.
%
% time1352 and data1352 available for use
% for Twitter Mentions of @MATLAB
%
% Number of Followers for MATLAB on Twitter
%   time vector is: time1304
%   data vector is: data1304

subplot(2,1,1)

% Fit MATLAB Follower growth
[p,S,mu] = polyfit(time1304,data1304,1);
p1 = [p(1)/mu(2) p(2)-p(1)*mu(1)/mu(2)];

% Project into the future
tf = [time1304; time1304(end)+1];
df = polyval(p1,tf);

% Predict the number for the next day
d=round(df(end));
t=datestr(time1304(end)+1,1);
s=sprintf('Prediction for %s: %d followers',t,d);

% Predict when it will reach a goal
goal = 8000;
g = sprintf('Will reach %d followers on ', goal);
g = [g datestr((goal - p1(2))/p1(1),1)];

% Was previous prediction correct?
[p,S,mu] = polyfit(time1304(1:end-1),data1304(1:end-1),1);
p2 = [p(1)/mu(2); p(2)-p(1)*mu(1)/mu(2)];
prev = polyval(p2,time1304(end-1)+1);
prev = round(prev);
gap = prev-data1304(end);
t=datestr(time1304(end),1);
p=sprintf('Prev Prediction for %s off by %d',t,gap);

% Plot the data and trend
plot(time1304,data1304,'-');
hold on
line(tf,df,'Color','magenta','LineStyle','-')
plot(time1304(end),prev, 'ro');
datetick
legend('Followers','Trend','Prev Prediction', 'Location', 'Northwest')
xlabel(s)
hold off

% Get normalized position for annotation
xrange = xlim;
xmin = xrange(1);
xmax = xrange(2);
yrange = ylim;
ymin = yrange(1);
ymax = yrange(2);

XPos = xmin+0.35*(xmax-xmin);
YPos1 = ymin+0.2*(ymax-ymin);
YPos2 = ymin+0.1*(ymax-ymin);
text(XPos,YPos1,p)
text(XPos,YPos2,g)

subplot(2,1,2)

% Pad the data to fit the timeline with another plot
time = [time1304(1:5); time1352; tf(end)];
data = [NaN; NaN; NaN; NaN; NaN; data1352; NaN];

% Get z-score of time1352
% z = (time1352-mean(time1352))/std(time1352);
% zfit = linspace(z(1),z(end), size(time1352,2));

% Get 4th order polynomial fit
% pz4 = polyfit(z,data1352,4);
% yfit = polyval(pz4,zfit); % fitted data
% xfit = linspace(time1352(1),time1352(end), ...
%    size(time1352,2));
% keep = yfit >=0; %eliminate sub-zero

% ymin = fix(min(data1352));
% ymax = ceil(max(data1352));

% Smoothed Curve - 7 Day Moving Average
windowSize = 7;
mv = filter(ones(1,windowSize)/windowSize,1,data1352);

% plot(time, data, 'o-');
plot(time,data,'Color',[0.8 0.8 1])
hold on
% plot(xfit(keep),yfit(keep),'m-')
line(time1352,mv,'Color','blue','LineWidth',1);

% ylim([ymin-1 ymax+1])
% set(gca,'YTick',ymin-1:ymax+1)
datetick