Code covered by the BSD License  

Highlights from
Updating MATLAB(R) figure inserted on a Excel(R) Sheet

from Updating MATLAB(R) figure inserted on a Excel(R) Sheet by Martti
How to insert an automatically updating MATLAB(R) figure to an Excel(R) sheet.

...
function [sysLoad, sysLoadCI, sysLoadSD, path] = ...
    estimateSingleDayFigure(energyData, DayType, dayOfWeek, timeOfDay, width, height)

% estimateSingleDay(energyData, DayType, dayOfWeek, timeOfDay)
%   Estimates energy usage for a particular day and time based on
%   historical data.
%
%   Inputs:
%     energyData - historical energy usage data
%     DayType    - information on the day of the week
%     dayOfWeek  - the day of interest
%     timeOfDay  - the hour(s) of interest

% List of days
allDays   = {'Monday', 'Tuesday', 'Wednesday', 'Thursday', ...
  'Friday', 'Saturday', 'Sunday'};

% Extract data for a particular day
singleDay = energyData(DayType == strmatch(char(dayOfWeek), allDays), :);

% Calculate statistics
[singleDayMean, singleDayStDev, singleDayCI] = normfit(singleDay);

% Extract statistics for particular time of day
sysLoad   = singleDayMean(timeOfDay);
sysLoadCI = singleDayCI(:, timeOfDay);
sysLoadSD = singleDayStDev(timeOfDay);

% Create Visualization
% CREATE HIDDEN FIGURE (hidden if deployed, visible otherwise)
if isdeployed,
    visiblestate = 'off';
else
    visiblestate = 'on';
end;
tempfigure = figure( ...
    'visible',visiblestate, ...
    'PaperPositionMode', 'auto', ...
    'color','w', ...
    'position', [0 0 width height], ...
     'alphamap', [.1;1]);
tempaxes = axes('parent', tempfigure,  'visible', visiblestate);
% Visualize:
plot(singleDay');
hold(tempaxes, 'on');
plot(singleDayMean, 'linewidth', 4);
plot([timeOfDay;timeOfDay], sysLoadCI, 'r', 'linewidth', 2)
h = plot(timeOfDay, sysLoad, 'r.-', 'markersize', 30, 'linewidth', 2);
xlabel('hours', 'parent', tempaxes);ylabel('system load (MW)');
ampm = {'AM', 'PM'};
title(sprintf('Estimate for %ss', char(dayOfWeek)));
legend(h, ...
  sprintf('%s = %5.2f, %s = %5.2f\n(@ %d %s)', ...
  '\mu', ...
  sysLoad, ...
  '\sigma', ...
  sysLoadSD, ...
  mod(timeOfDay-1,12)+1, ...
  ampm{floor(timeOfDay/12)+1}), ...
  'Location', 'NorthWest');
hold(tempaxes, 'off')

% Save to file
path = [tempname '.bmp'];
print(tempfigure, '-r0', '-dbmp', path);
close(tempfigure);

Contact us at files@mathworks.com