function [] = subfiguretest(str)
% SUBFIGURETEST tests the workings of function SUBFIGURE. This function is
% simply one big switchyard. To see the options, which is a list of valid
% string arguments for this function, call this:
%
% subfiguretest('options')
%
%
if nargin==0
str = 'I_didnt_read_the_help';
end
switch str
case 'basic'
home
% This case tests various tilings.
fprintf('\n')
disp('Calling: subfigure(4,4,{1:16})')
fprintf('\n')
subfigure(4,4,{1:16});
pause(2);
close all
%------------------------------------------------------------
disp('Calling: subfigure(2,2,{1:4})')
fprintf('\n')
subfigure(2,2,{1:4});
pause(2);
close all
%------------------------------------------------------------
disp('Calling: subfigure(2,1,{1:2})')
fprintf('\n')
subfigure(2,1,{1:2});
pause(2);
close all
%------------------------------------------------------------
disp('Calling: subfigure(1,2,{1:2})')
fprintf('\n')
subfigure(1,2,{1:2});
pause(2);
close all
%------------------------------------------------------------
disp('Calling: subfigure(6,6,{1:36})')
fprintf('\n')
subfigure(6,6,{1:36});
pause(2);
close all
%------------------------------------------------------------
disp('Calling: subfigure(6,1,{1:6})')
fprintf('\n')
subfigure(6,1,{1:6});
pause(2);
close all
%------------------------------------------------------------
disp('Calling: subfigure(1,6,{1:6})')
fprintf('\n')
subfigure(1,6,{1:6});
pause(2);
close all
%------------------------------------------------------------
disp('Calling: subfigure(2,2,1)')
disp(' subfigure(2,2,2)')
disp(' subfigure(2,1,2)')
fprintf('\n')
subfigure(2,2,1);
subfigure(2,2,2);
subfigure(2,1,2);
pause(2);
close all
%------------------------------------------------------------
disp('Calling: subfigure(2,2,1)')
disp(' subfigure(2,2,3)')
disp(' subfigure(1,2,2)')
fprintf('\n')
subfigure(2,2,1);
subfigure(2,2,3);
subfigure(1,2,2);
pause(2);
close all
case 'replace'
home
% This case checks if passing in 'replace' works or not.
fprintf('\n')
disp('Calling: subfigure(2,2,1)')
disp(' subfigure(2,2,2)')
disp(' subfigure(2,1,2)')
subfigure(2,2,1);
subfigure(2,2,2);
subfigure(2,1,2);
pause(1);
disp('Calling: subfigure(1,1,1,''replace'')')
subfigure(1,1,1,'replace');
pause(2);
number_of_figures = numel(get(0,'children')); %Should be one
if number_of_figures==1
disp(' Passed replace test 1')
else
disp(' Failed replace test 1')
end
close all
pause(2);
%------------------------------------------------------------
fprintf('\n')
disp('Calling: subfigure(2,2,1)')
disp(' subfigure(2,2,2)')
disp(' subfigure(2,1,2)')
subfigure(2,2,1);
subfigure(2,2,2);
subfigure(2,1,2);
pause(1);
disp('Calling: subfigure(2,2,3,''replace'')')
subfigure(2,2,3,'replace','color','red');
pause(2);
number_of_figures = numel(get(0,'children')); %Should be three
if number_of_figures==3
disp(' Passed replace test 2')
else
disp(' Failed replace test 2')
end
close all
case 'sixby'
% This case tests if the non-menubar tiling matches that with menu
% bars added. We want the figures on the left to be the same size
% as the figures on the right.
%------------------------------------------------------------
home
fprintf('\n')
ii = [1 2 3 7 8 9 13 14 15 19 20 21 25 26 27 31 32 33];
ST = sprintf('%i ',ii);
disp(['Calling: subfigure(6,6,{',ST,'},''menub'',''none'')'])
subfigure(6,6,{ii},'menub','none');
ii = [4 5 6 10 11 12 16 17 18 22 23 24 28 29 30 34 35 36];
ST = sprintf('%i ',ii);
disp(['Calling: subfigure(6,6,{',ST,'})'])
fprintf('\n')
subfigure(6,6,{ii});
pause(2)
close all
case 'twoby'
% This case tests if the non-menubar tiling matches that with menu
% bars added. We want the figures on the left to be the same size
% as the figures on the right.
home
fprintf('\n')
ii = [1 3];
ST = sprintf('%i %i',ii);
disp(['Calling: subfigure(2,2,{',ST,'},''menub'',''none'')'])
subfigure(2,2,{ii},'menub','none');
ii = [2 4];
ST = sprintf('%i %i',ii);
disp(['Calling: subfigure(2,2,{',ST,'})'])
fprintf('\n')
subfigure(2,2,{ii});
pause(2)
close all
case 'stackem'
% This case tests if figures with and without menubars stack nicely
% in case user wants to call a mix.
home
fprintf('\n')
disp('To see calling code, call: edit subfiguretest')
fprintf('\n')
N = 6;
subfigure(N,N,{linspace(1,N^2,N)},'Name','my1','menub','n')
subfigure(N,N,{linspace(N,N^2-N+1,N)},'Name','my2','menub','f')
subfigure(N,N,2:5,'menub','n')
subfigure(N,N,32:35)
subfigure(N,N,[13 20])
subfigure(N,N,[17 24],'menub','n')
pause(4)
close all
case 'propvals'
% This case tests if passing property/value pairs is successful.
home
fprintf('\n')
disp(['Calling: subfigure(4,4,1,''units'',''normalized'',',...
'''Number'',''off'')'])
subfigure(4,4,1,'units','normalized','Number','off')
if strmatch(get(gcf,'units'),'normalized')
disp(' Passed property assignment 1.')
else
disp(' Failed property assignment 1.')
end
fprintf('\n')
disp('Calling: subfigure(4,4,5,''menub'',''n'')')
disp('Calling: subfigure(4,4,9,''replace'',''color'',''r'')')
subfigure(4,4,5,'menub','n')
subfigure(4,4,9,'rep','color','r')
if all(get(gcf,'color')==[1 0 0])
disp(' Passed property assignment 2.')
else
disp(' Failed property assignment 2.')
end
fprintf('\n')
pause(1)
close all
case 'bigfig'
% This case tests if the large figure indeed has the correct
% postitioning when called to span the postitions of many smaller
% figures.
home
for ii = 1:10
T = randperm(25);
T = T(1:3);
ST = sprintf('%i %i %i',T);
disp(['Calling: subfigure(5,5,{',ST,'})'])
subfigure(5,5,{T});
pause(.5)
disp(['Replacing with: subfigure(5,5,[',ST,'],''replace'')'])
subfigure(5,5,T,'replace');
pause(.5)
close
fprintf('\n')
end
case 'options'
% User wants to know what options there are for testing.
home
fprintf('\n')
disp('Here is a list of arguments to this function and a ')
disp('description of what each one does.')
disp('Most tests do multiple tasks with brief pauses in between.')
disp('All arguments should be strings, as indicated below')
fprintf('\n')
disp('''basic'' Tests 9 configurations, pause(2) in between each.')
disp('''replace'' Tests if calling with ''replace'' works or not.')
disp('''twoby'' Tests if menu-ed and non-menued fit nicely in 2x2.')
disp('''sixby'' Tests if menu-ed and non-menued fit nicely in 6x6.')
disp('''stackem'' Tests if menu-ed and non-menu-ed figures stack')
disp(' nicely in a complex arraingement.')
disp('''error'' See if common user errors are caught correctly.')
disp('''propvals'' Tests if prop/val pairs are passed correctly.')
disp('''bigfig'' 10 tests if the position-spanning figure works.')
disp(' Plots 3 random subfigures, then plots the large figure')
disp(' that spans the positions of the three subfigures.')
fprintf('\n\n')
case 'error'
home
try
disp('subfigure(3,4) Not enough inputs.' )
subfigure(3,4);
catch
T = lasterror;
if (T.stack(1).line)==47
disp('Errored correctly.')
else
disp('Errored incorrectly.')
end
end
fprintf('\n')
try
disp('subfigure(3,4,4,''pizza'') Unknown 4th option.')
subfigure(3,4,4,'pizza');
catch
T = lasterror;
if (T.stack(1).line)==64
disp('Errored correctly.')
else
disp('Errored incorrectly.')
end
end
fprintf('\n')
try
disp('subfigure(3,2,''c'') 3rd arg must be numberic or ''all''.')
subfigure(3,2,'c');
catch
T = lasterror;
if (T.stack(1).line)==94
disp('Errored correctly.')
else
disp('Errored incorrectly.')
end
end
fprintf('\n')
try
disp('subfigure(3,{4},6) First two inputs scalar.')
subfigure(3,{4},6);
catch
T = lasterror;
if (T.stack(1).line)==107
disp('Errored correctly.')
else
disp('Errored incorrectly.')
end
end
fprintf('\n')
try
disp('subfigure([1 3],4,6) First two inputs scalar.')
subfigure([1 3],4,6);
catch
T = lasterror;
if (T.stack(1).line)==107
disp('Errored correctly.')
else
disp('Errored incorrectly.')
end
end
fprintf('\n')
try
disp('subfigure(3,''b'',6) Args must be numeric.')
subfigure(3,'b',6);
catch
T = lasterror;
if (T.stack(1).line)==113
disp('Errored correctly.')
else
disp('Errored incorrectly.')
end
end
fprintf('\n')
try
disp('subfigure(-3,-3,6) Args must be >=1.')
subfigure(-3,-3,6);
catch
T = lasterror;
if (T.stack(1).line)==113
disp('Errored correctly.')
else
disp('Errored incorrectly.')
end
end
fprintf('\n')
try
disp('subfigure(3,2.3,6) Args must be integers.')
subfigure(3,2.3,6);
catch
T = lasterror;
if (T.stack(1).line)==113
disp('Errored correctly.')
else
disp('Errored incorrectly.')
end
end
fprintf('\n')
try
disp('Calling: subfigure(3,4,20) c>a*b' )
subfigure(3,4,20);
catch
T = lasterror;
if (T.stack(1).line)==117
disp('Errored correctly.')
else
disp('Errored incorrectly.')
end
end
otherwise
subfiguretest('options')
end
% Below is a way to see if the figures are filling the screen in the
% horizontal direction. There should be a 1 pixel buffer on either side of
% a figure block. I.e., SUMM should equal SCR(3)-2 for different N values.
%
% SCR = get(0,'screensize')
% N = 4;
% H = subfigure(N,N,{1:N},'replace','menub','n');pause(.5)
% T = cell2mat(get(H,'outerpos'));
% SUMM = sum(T(:,3))