Code covered by the BSD License

# Demo files for "MATLAB for Excel Users" webinar

### Jiro Doke (view profile)

27 Aug 2010 (Updated )

This is the demo used in March 22, 2011 webinar "MATLAB for Excel Users".

createSurfaceFit(thisHour, thisTemp, thisPower)
```function [fitresult, gof] = createSurfaceFit(thisHour, thisTemp, thisPower)
%CREATESURFACEFIT(THISHOUR,THISTEMP,THISPOWER)
%  Fit surface to data.
%
%  Data for 'untitled fit 1' fit:
%      X Input : thisHour
%      Y Input : thisTemp
%      Z output: thisPower
%      Weights : (none)
%
%  Output:
%      fitresult : an sfit object representing the fit.
%      gof : structure with goodness-of fit info.
%

%  Auto-generated by MATLAB on 02-Jun-2009 21:05:45

% Copyright 2010 The MathWorks, Inc.

%% Fit: 'untitled fit 1'.
ft = fittype( 'a0 + a1*cos(w*x) + b1*sin(w*x) + a2*cos(2*w*x) + b2*sin(2*w*x) + c1*y^2 + c2*y', 'indep', {'x', 'y'}, 'depend', 'z' );
opts = fitoptions( ft );
opts.Display = 'Off';
opts.Lower = [-Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf];
opts.StartPoint = [0.394215930761206 0.245616861988953 0.989843778259555 0.812507848600185 0.812489348000533 0.945905873253906 0.185190354480726 0.508414206620238];
opts.Upper = [Inf Inf Inf Inf Inf Inf Inf Inf];
opts.Weights = zeros(1,0);
[fitresult, gof] = fit( [thisHour, thisTemp], thisPower, ft, opts );

% Plot fit with data.
figure( 'Name', 'Power Demand', 'NumberTitle', 'off');
h = plot( fitresult, [thisHour, thisTemp], thisPower );
grid on
% Label axes
xlabel( 'Hour' );
ylabel( 'Temperature (\circF)' );
zlabel( 'Power (MW)' );

```