Code covered by the BSD License

# Files used in "Matlab For Excel Users" (Japanese version) / 「ExcelユーザのためのMATLAB」Webセミナーのファイル

### Teja Muppirala (view profile)

Webinar files: "MATLAB for Excel Users" (Japanese) Webセミナー「ExcelユーザのためのMATLAB」で使われたファイルです

MainAnalysis.m
%% fXg[V - d͎v̗\
% ̃fXg[Vł́A
% ߋ̓d͋ʂ̃f[^ɊÂA
% d͎v\邽߂̉͂̎sĂ܂B
% ɂ́AjOCxȂǂ̏܂񂾁A
% 2006Nɂ閈̓d͋ʂ̃f[^܂B
% ̏pA̎ƊOCɂA
% ̓d͎v\邽߂̃f쐬܂B

% Copyright 2009 The MathWorks, Inc.

%% f[^̃C|[g
% ͂߂ɁAExcelt@Cf[^̃C|[gs܂B

importfile('2006Data.xls');

%% O
% 荞񂾃f[^mFOɁA
% jƌɑΉ镶쐬Ă܂B

dayText =  {'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'};
monthText =  {'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', ...
'Aug', 'Sep', 'Oct', 'Nov', 'Dec'};

%% f[^̊mF
% 荞񂾃f[^邱ƂŁAlXȓ@܂B
% Ⴆ΂ł́A
% Ɠd͋ʂƂ̊֌WUz}ŊmFĂ݂܂B

scatter(Hour, Power);

%%
% boxplot()֐pƁA
% NԂʂf[^̕z薾mɕ悤ɂȂ܂B
%
% *Power vs. Hour*
%
% ԂƑ̋ʂA
% ԂɔׂďȂȂĂ邱Ƃ܂B

boxplot(Power, Hour);
xlabel('Hour');

%%
% l̕@ŁÃ^CXP[łmFĂ݂܂傤B
%
% *Power vs. Day*
%
% 1Pʂł݂ꍇ̓d͋ʂ̕ϓ́A
% قǑ傫͖悤łB

figure;
boxplot(Power, Day, 'plotstyle', 'compact');
xlabel('Day');

%%
% ܂AjPʂ̃XP[łSf[^mFĂ݂܂B
%
% *Power vs. Day of Week*
%
% ɔׂāA
% y̓d͋ʂ͏ȂȂĂ邱Ƃ܂B

figure;
boxplot(Power, DayOfWeek, 'labels', dayText(unique(DayOfWeek)));
xlabel('Day of Week');

%%
% ŌɁAPʂ̃XP[őSf[^mFĂ݂܂B
%
% *Power vs. Month*
%
% G߂ɂ苟ʂωĂ邱Ƃ܂B
% C̒Ⴂ͒g[A
% C̍͗[葽gp邽߁A
% ̎d͋ʂΓIɍȂĂ܂B

figure;
boxplot(Power, Month, 'labels', monthText(unique(Month)));
xlabel('Month');

%% Ot̃JX^}CY
% ɁA1Ñf[^𖈎ƂɃvbgA
% P̘Af[^Ƃĕ\Ă݂܂B
% ̂߂ɁA܂ef[^_ɑΉA
% VAȓtf[^쐬܂B

serialDate = datenum(2006, Month, Day, Hour, 0, 0);

%%
% ŁAƓd͋ʂ̊֌W\ł悤ɂȂ܂B
% ł͂ɁAƋC̊֌WOt֒ǉ\܂B

createfigure(serialDate, Power, Temperature)

%%
% Ot̃Y[CsƁA1Pʂł̕ω1TԒPʁA
% Pʂł̓d͋ʂ̕ωmFł܂B
% f[^7PʁA
% ܂1TԒPʂ̎Ă悤Ɍ܂B
% ܂ƏT̕ω͖炩ɈقȂ邱Ƃ܂B
%
% ɁANԂʂāA
% C傫ɂ₩ɕωĂ邱ƂmFł܂B
% ̂ƂAC͓d͋ʂɑ΂ĒIȕϓɉeA
% ͒ZIȕϓɉeĂƍl܂B

%% Ȗʋߎ
% ̓@ɊÂA
% d͋ʂ͎ƋC̊֐łƉ肵܂B
%
% wf̋ߎɂ́ASẴf[^ZbgpA
% Iɒôp܂B
% ܂ƏT͈قȂU镑Ă邽߁A
% ؂蕪Ã͕f[^𔲂o܂B
% ܂ACω̉eL͂ɃJo[邽߂ɁA
% C̒Ⴂł1ƁA
% C̍ł7̃f[^𔲂o܂B
%
% ͂߂ɁA17̃̕f[^𒊏o܂B
% f[^ɂ́Ajlȉ̂悤ɋLڂĂ܂B
%
% * Monday      = 1
% * Tuesday     = 2
% * Wednesday   = 3
% * Thursday    = 4
% * Friday      = 5
% * Saturday    = 6
% * Sunday      = 7
%
% ɊÂASf[^A
% uA17ṽf[^R[h̃CfbNX擾܂B

idx = DayOfWeek < 6 & ismember(Month, [1 7]);

%%
% 擾CfbNXA
% ECEd͋ʂ̑Sf[^ɓKpA
% Yf[^R[ĥ݂𒊏o܂B

thisHour = Hour(idx);
thisTemp = Temperature(idx);
thisPower = Power(idx);

%%
% ̃f[^ȉ̐ŋߎ܂B
%
% $$a_0 + a_1*cos(\omega t) + b_1*sin(\omega t) + a_2*cos(2\omega t) + % b_2*sin(2\omega t) + c_1*y^2 + c_2*y$$
%
%  |t| ͎A |y| ͋C\Ă܂B
%
% (ȉ̊֐Surface Fitting ToolɂĎꂽMATLABt@CłB)

[model, goodness] = createSurfaceFit(thisHour, thisTemp, thisPower)

%%
% If[^R[hɊÂߎȖʂA
% L̃Otŕ\Ă܂B
% ̊֐̖߂l |model| pƁA
% d͎v̗\l𓾂邱Ƃł܂B
%
% Ⴆ΁A12ŊOCێ20x̂Ƃ̓d͎v̗\ĺA
% ̂悤ɂē邱Ƃł܂B

model(12, 20)

%%
% ̗\l95%MԂ͈ȉœ܂B

predint(model, [12, 20])

%% ܂Ƃ
% ȏ̃XNvgɂAߋ̓d͋ʂ̃f[^A
% ̓d͎vA
% ƊOC̊֐ŗ\ߎf𓾂邱Ƃł܂B
% ͍ŗǂ̋ߎʂł͂Ȃm܂񂪁A
% f̑If[^̑OsA
% قȂf[^Zbgŉ͂sȂǁA
% lXȎs𑱂邱ƂŁAǂߎʂ𓾂邱Ƃł܂B