This is a static copy of a profile reportHome
scribe.legend.methods>lscan (9 calls, 0.481 sec)
Generated 05-Aug-2011 13:00:48 using cpu time.
subfunction in file /usr/local/MATLAB/R2011a/toolbox/matlab/scribe/@scribe/@legend/methods.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
914 | pop(j,i) = sum(sum((Xdata >... | 51 | 0.131 s | 27.3% |  |
768 | [xk,yk,zk] = localGetLineData(... | 39 | 0.120 s | 25.0% |  |
889 | Xdata = Xdata(in); | 9 | 0.044 s | 9.1% |  |
770 | Ydata=[Ydata,yk]; | 39 | 0.033 s | 6.8% |  |
935 | newpop = filter2(ones(3),pop); | 2 | 0.022 s | 4.5% |  |
All other lines | | | 0.131 s | 27.3% |  |
Totals | | | 0.481 s | 100% | |
Children (called functions)
Code Analyzer results
Line number | Message |
768 | The value assigned to variable 'zk' might be unused. |
769 | The variable 'Xdata' appears to change size on every loop iteration. Consider preallocating for speed. |
770 | The variable 'Ydata' appears to change size on every loop iteration. Consider preallocating for speed. |
774 | The variable 'Xdata' appears to change size on every loop iteration. Consider preallocating for speed. |
775 | The variable 'Ydata' appears to change size on every loop iteration. Consider preallocating for speed. |
782 | The variable 'Xdata' appears to change size on every loop iteration. Consider preallocating for speed. |
783 | The variable 'Ydata' appears to change size on every loop iteration. Consider preallocating for speed. |
826 | The variable 'Xdata' appears to change size on every loop iteration. Consider preallocating for speed. |
827 | The variable 'Ydata' appears to change size on every loop iteration. Consider preallocating for speed. |
850 | The variable 'Xdata' appears to change size on every loop iteration. Consider preallocating for speed. |
851 | The variable 'Ydata' appears to change size on every loop iteration. Consider preallocating for speed. |
876 | The variable 'Xdata' appears to change size on every loop iteration. Consider preallocating for speed. |
877 | The variable 'Ydata' appears to change size on every loop iteration. Consider preallocating for speed. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 243 |
Non-code lines (comments, blank lines) | 53 |
Code lines (lines that can run) | 190 |
Code lines that did run | 86 |
Code lines that did not run | 104 |
Coverage (did run/can run) | 45.26 % |
Function listing
time calls line
704 function Pos = lscan(ha,plotChildren,wdt,hgt,tol,stickytol) %#ok
705
706 % Calculate tile size
9 707 cap = hgconvertunits(ancestor(ha,'figure'),...
708 get(ha,'Position'),get(ha,'Units'),...
709 'normalized',get(ha,'Parent'));
710
9 711 islogx = strcmpi(get(ha,'XScale'),'Log');
9 712 islogy = strcmpi(get(ha,'YScale'),'Log');
9 713 xlim=get(ha,'Xlim');
9 714 ylim=get(ha,'Ylim');
715
9 716 if islogx
717 xlim = log10(xlim);
718 end
9 719 if islogy
720 ylim = log10(ylim);
721 end
722
9 723 if ~all(isfinite(xlim)) || ~all(isfinite(ylim))
724 % If any of the public limits are inf then we need the actual limits
725 % by getting the hidden deprecated RenderLimits.
726 oldstate = warning('off','MATLAB:HandleGraphics:NonfunctionalProperty:RenderLimits');
727 renderlimits = get(ha,'RenderLimits');
728 warning(oldstate);
729 xlim = renderlimits(1:2);
730 ylim = renderlimits(3:4);
731 end
732
9 733 H=ylim(2)-ylim(1);
9 734 W=xlim(2)-xlim(1);
735
9 736 buffH = 0.03*H;
9 737 buffW = 0.03*W;
9 738 Hgt = hgt*H/cap(4);
9 739 Wdt = wdt*W/cap(3);
9 740 Thgt = H/max(1,floor(H/(Hgt+buffH)));
9 741 Twdt = W/max(1,floor(W/(Wdt+buffW)));
742
743 % If there is only room for one tile, use the size of the legend as the
744 % tile size.
9 745 tallLegend = false;
9 746 if H-Thgt < eps
1 747 Thgt = Hgt+buffH;
1 748 tallLegend = true;
1 749 end
9 750 longLegend = false;
9 751 if W-Twdt < eps
4 752 Twdt = Wdt+buffW;
4 753 longLegend = true;
4 754 end
755
9 756 dh = (Thgt - Hgt)/2;
9 757 dw = (Twdt - Wdt)/2;
758
759 % Get data, points and text
0.01 9 760 Kids=[findall(ha,'type','line'); ...
761 findall(ha,'type','patch'); ...
762 findall(ha,'type','surface'); ...
763 findall(ha,'type','text')];
9 764 Xdata=[];Ydata=[];
9 765 for i=1:length(Kids),
102 766 type = get(Kids(i),'type');
102 767 if strcmp(type,'line')
0.12 39 768 [xk,yk,zk] = localGetLineData(Kids(i));
0.01 39 769 Xdata=[Xdata,xk];
0.03 39 770 Ydata=[Ydata,yk];
63 771 elseif strcmp(type,'patch') || strcmp(type,'surface')
772 xk = get(Kids(i),'Xdata');
773 yk = get(Kids(i),'Ydata');
774 Xdata=[Xdata,xk(:)'];
775 Ydata=[Ydata,yk(:)'];
0.01 63 776 elseif strcmp(get(Kids(i),'type'),'text'),
63 777 tmpunits = get(Kids(i),'units');
63 778 set(Kids(i),'units','data')
63 779 tmp=get(Kids(i),'Position');
63 780 ext=get(Kids(i),'Extent');
63 781 set(Kids(i),'units',tmpunits);
63 782 Xdata=[Xdata,[tmp(1) tmp(1)+ext(3)]];
63 783 Ydata=[Ydata,[tmp(2) tmp(2)+ext(4)]];
63 784 end
102 785 end
786 % The legend may point to children that are not in the same axes. These
787 % children require a bit of preprocessing:
9 788 plotChildren(~ishandle(plotChildren)) = [];
0.01 9 789 otherKids = setdiff([findall(plotChildren,'type','line'); ...
790 findall(plotChildren,'type','patch'); ...
791 findall(plotChildren,'type','surface'); ...
792 findall(plotChildren,'type','text')],Kids);
793
0.02 9 794 peerTransform = localGetAxesTransform(ha);
0.01 9 795 invPeerTransform = pinv(peerTransform);
796
9 797 if islogx
798 Xdata = log10(Xdata);
799 end
9 800 if islogy
801 Ydata = log10(Ydata);
802 end
803
9 804 for i=1:length(otherKids),
805 type = get(otherKids(i),'type');
806 hAx = ancestor(otherKids(i),'Axes');
807 isOtherLogX = strcmpi(get(hAx,'XScale'),'Log');
808 isOtherLogY = strcmpi(get(hAx,'YScale'),'Log');
809 if strcmp(type,'line')
810 [xk,yk,zk] = localGetLineData(otherKids(i));
811 if isOtherLogX
812 xk = log10(xk);
813 end
814 if isOtherLogY
815 yk = log10(yk);
816 end
817 dataVec = [xk(:)';yk(:)';zk(:)'];
818 currTransform = localGetAxesTransform(hAx);
819 newData = localDoTransform(invPeerTransform,localDoTransform(currTransform,dataVec));
820 if islogx
821 newData(1,:) = 10.^newData(1,:);
822 end
823 if islogy
824 newData(2,:) = 10.^newData(2,:);
825 end
826 Xdata=[Xdata,newData(1,:)];
827 Ydata=[Ydata,newData(2,:)];
828 elseif strcmp(type,'patch') || strcmp(type,'surface')
829 xk = get(otherKids(i),'Xdata');
830 yk = get(otherKids(i),'Ydata');
831 if isvector(x)
832 [xk,yk] = meshgrid(xk,yk);
833 end
834 if isOtherLogX
835 xk = log10(xk);
836 end
837 if isOtherLogY
838 yk = log10(yk);
839 end
840 zk = get(otherKids(i),'Zdata');
841 dataVec = [xk(:)';yk(:)';zk(:)'];
842 currTransform = localGetAxesTransform(hAx);
843 newData = localDoTransform(invPeerTransform,localDoTransform(currTransform,dataVec));
844 if islogx
845 newData(1,:) = 10.^newData(1,:);
846 end
847 if islogy
848 newData(2,:) = 10.^newData(2,:);
849 end
850 Xdata=[Xdata,newData(1,:)];
851 Ydata=[Ydata,newData(2,:)];
852 elseif strcmp(get(otherKids(i),'type'),'text'),
853 tmpunits = get(otherKids(i),'units');
854 set(otherKids(i),'units','data')
855 tmp=get(otherKids(i),'Position');
856 ext=get(otherKids(i),'Extent');
857 set(otherKids(i),'units',tmpunits);
858 xk = [tmp(1) tmp(1)+ext(3)];
859 yk = [tmp(2) tmp(2)+ext(4)];
860 if isOtherLogX
861 xk = log10(xk);
862 end
863 if isOtherLogY
864 yk = log10(yk);
865 end
866 zk = [0 0];
867 dataVec = [xk(:)';yk(:)';zk(:)'];
868 currTransform = localGetAxesTransform(hAx);
869 newData = localDoTransform(invPeerTransform,localDoTransform(currTransform,dataVec));s
870 if islogx
871 newData(1,:) = 10.^newData(1,:);
872 end
873 if islogy
874 newData(2,:) = 10.^newData(2,:);
875 end
876 Xdata=[Xdata,newData(1,:)];
877 Ydata=[Ydata,newData(2,:)];
878 end
879 end
880
881 % make sure xdata and ydata have same length
9 882 if ~isequal(length(Xdata),length(Ydata))
883 xydlength = min(length(Xdata),length(Ydata));
884 Xdata = Xdata(1:xydlength);
885 Ydata = Ydata(1:xydlength);
886 end
887 % xdata and ydata must have same dimensions
0.01 9 888 in = isfinite(Xdata) & isfinite(Ydata);
0.04 9 889 Xdata = Xdata(in);
9 890 Ydata = Ydata(in);
891
892 % Determine # of data points under each "tile"
893 % Since the tile-size may not evenly go into the width or height, make this
894 % a two-pass approach taking only the unique positions.
0.01 9 895 xp = unique([(0:Twdt:W-Twdt) (W-Twdt:-Twdt:0)] + xlim(1));
896 % If we are in a scenario with a longer legend, be sure not to ignore the
897 % middle as a valid location.
9 898 if longLegend
4 899 xp(end+1) = (W/2 - (Wdt+buffW)/2)+xlim(1);
4 900 end
901
9 902 yp = unique([(H-Thgt:-Thgt:0) (0:Thgt:H-Thgt)]+ ylim(1));
903 % If we are in a scenario with a taller legend, be sure not to ignore the
904 % middle as a valid location.
9 905 if tallLegend
1 906 yp(end+1) = (H/2 - (Hgt+buffH)/2)+ylim(1);
1 907 end
908
9 909 wtol = Twdt / 100;
9 910 htol = Thgt / 100;
9 911 pop = zeros(length(yp),length(xp));
9 912 for j=1:length(yp)
20 913 for i=1:length(xp)
0.13 51 914 pop(j,i) = sum(sum((Xdata > xp(i)-wtol) & (Xdata < xp(i)+Twdt+wtol) & ...
915 (Ydata > yp(j)-htol) & (Ydata < yp(j)+Thgt+htol)));
51 916 end
20 917 end
918
919 % If the "XDir" property is set to reverse, then the tiles need to be
920 % flipped:
0.02 9 921 if strcmpi(get(ha,'XDir'),'Reverse')
922 pop = fliplr(pop);
923 end
924 % If the "YDir" property is set to reverse, then the tiles need to be
925 % flipped:
9 926 if strcmpi(get(ha,'YDir'),'Reverse')
927 pop = flipud(pop);
928 end
929
9 930 if all(pop(:) == 0), pop(1) = 1; end
931
932 % Cover up fewest points. After this while loop, pop will
933 % be lowest furthest away from the data
9 934 while any(pop(:) == 0)
0.02 2 935 newpop = filter2(ones(3),pop);
2 936 if all(newpop(:) ~= 0)
2 937 break;
938 end
939 pop = newpop;
940 end
941
0.01 9 942 [j,i] = find(pop == min(pop(:)));
9 943 xp = xp - xlim(1) + dw;
9 944 yp = yp - ylim(1) + dh;
9 945 Pos = [cap(1)+xp(i(end))*cap(3)/W
9 946 cap(2)+yp(j(end))*cap(4)/H];
Other subfunctions in this file are not included in this listing.