function h = canadaflag(flagleft, flagbottom, flagwidth)
%CANADAFLAG - Draws the Canadian flag within an existing axes
% or within a new figure if no input arguments are provided
%
%Syntax: h = canadaflag(flagleft, flagbottom, flagwidth);
% canadaflag; %No input arguments
%
%Inputs: flagleft - x-coordinate of lower left corner
% flagbottom - y-coordinate of lower left corner
% flagwidth - width of the flag expressed in x-axis units
%
%Outputs: h - structure with handles for the 3 red patches of the Canada flag
%
%Examples:
% x = (0:10)'; %Example 1
% y = x.^2; %Inserts a flag within existing axes
% plot(x,y)
% h = canadaflag(2,60,4);
%
% canadaflag; %Example 2 with no inputs or outputs
% h = canadaflag(-69.9,47, 1.5); %Example 3
%
%Other m-files required: none
%Subfunctions: none
%MAT-files required: canadaflag_xy
%
%See also: USFLAG (on Matlab Central File Exchange)
%Author: Denis Gilbert, Ph.D., physical oceanography
%Maurice Lamontagne Institute, Dept. of Fisheries and Oceans Canada
%email: gilbertd@dfo-mpo.gc.ca Web: http://www.qc.dfo-mpo.gc.ca/iml/
%September 2000; Last revision: 14-Feb-2002
%Check number of input arguments
if nargin == 0
%Draw a flag occupying an entire figure
flagleft = 0; flagbottom = 0;
flagwidth = 1;
screen = get(0, 'ScreenSize');
figure('Name','Canada flag','NumberTitle','Off','MenuBar','none',...
'Units','normalized','position',[0.25 0.25 0.5 0.25*screen(3)/screen(4)],...
'PaperPositionMode','auto')
axes('visible','off','position',[0 0 1 1])
axis tight
elseif nargin ~= 3
error('Must provide 0 or 3 input arguments');
end
aspectratio = get(gca,'DataAspectRatio');
set(gca,'DataAspectRatioMode','manual');
flagheight = flagwidth/2 * (aspectratio(2)/aspectratio(1));
%Ensure the width of the flag will appear twice its height regardless of parent axes dataaspectratio
load canadaflag_xy
%load these variables: xlband; ylband; xrband; yrband; xleaf; yleaf;
%Construct x-coordinates of the red patches
xlband = flagleft + xlband*flagwidth;
xrband = flagleft + xrband*flagwidth;
xleaf = flagleft + xleaf*flagwidth;
%Construct y-coordinates of the red patches
ylband = flagbottom + ylband*flagheight;
yrband = flagbottom + yrband*flagheight;
yleaf = flagbottom + yleaf*flagheight;
%DRAW the flag
h.lband = patch(xlband, ylband,'r'); %left band
h.rband = patch(xrband, yrband,'r'); %right band
h.leaf = patch(xleaf, yleaf, 'r'); %maple leaf