% Example usage of the logger class.
% ==========================================================================
% Author: Pavan Mallapragada
% Organization: Massachusetts Institute of Technology
% Contact: <pavan_m@mit.edu>
% Created: Oct 01, 2011
% ==========================================================================
l = logger;
tic;
sumval = 0;
for i = 1:100,
pause(0.001);
my_output_1 = 10*rand;
height = 1.5*my_output_1 + 5*rand;
% Log my_output_1 variable as 'weight'
l.logVal('weight', my_output_1);
% Log height variable as 'weight'; no need to specify the string
% if same variable is used in the log
l.logIt(height);
sumval = sumval + my_output_1 + height;
s.r1 = my_output_1;
s.r2 = height;
s.r3 = 'Some Results';
if my_output_1 > 6
l.logWarn(['Height exceeded 6 at ' num2str(i)], true);
end
% Store every 10th
if mod(i,10) == 0,
l.logMesg([ num2str(i) ' entries logged with sum = ' num2str(sumval)], 1);
l.logVal('time',toc);
l.logVal('sum',sumval);
l.logObj('result',s);
end
end
% Set descriptions of variables for plots
l.setDesc('weight','Weight of Subjects');
l.setDesc('height','Height of Subjects');
l.setDefaultDesc('Subject ID');
% Plot several variables from the logger object.
figure; l.plot2Vars('weight','height','LineWidth', 2, 'Color','r');
figure; l.plotVar('weight','LineWidth', 2, 'Color','r');
figure; l.plotVar('height','LineWidth', 2, 'Color','r');
figure; l.plotFofVar('weight',@sin, 'LineWidth', 2, 'Color','r');
figure; l.plotFofVar('height',@log, 'LineWidth', 2, 'Color','r');
figure; l.plotFofVar('time',@cumsum, 'LineWidth', 2, 'Color','r');