No BSD License  

Highlights from
figIconNums

image thumbnail
from figIconNums by Todd Pataky
Replaces figure icons with figure numbers overlayed on a MATLAB icon

figIconNums()
function [] = figIconNums()

%FIGICONNUMS  Changes figure icons by overlaying figure numbers on a MATLAB icon   
%
%Example:
% figure(1)
% figure(5)
% figure(17)
% figure(84)
% figIconNums

%>>> Note that figIconNums.m creates a dummy window from which it creates
%images of the digits.





%(1) Find figures:
fignums = findobj('type','figure');
if isempty(fignums)
    fprintf('No MATLAB figure windows are open. Exiting.\n\n');
    return
end


%(2) Load image icon:  (from the MATLAB installation)
fname = fullfile(matlabroot,'toolbox','matlab','timeseries','matlabicon.gif');
icon0 = 2.5*imread(fname);   %brighten image by multiplying by 2.5


%(3) Generate images from number strings:
%-----See "Adding text to images" in MATLAB Help ("The Image Object and Its Properties")
[X] = num2img;
    function [X] = num2img()
        X = uint8(zeros(32,32,length(fignums)));    %the Matlab icon is 32x32 pixels
        figure                                      %open a dummy figure from which to grab the number string images
        th = text(26,10,'','units','pixels');       %create a dummy text object
        set(th,'fontname','arial','fontsize',21,'fontweight','bold',...
            'horizontalalignment','center','verticalalignment','bottom');
        for k=1:length(fignums)   %#ok<FXUP>
            set(th,'string',fignums(k))
            F = getframe(gca,[10 11 32 32]);
            X(:,:,k) = F.cdata(:,:,1);
        end
        close(gcf)                                  %close the dummy figure
    end


%(4) Add figure numbers to figure icons:
for k=1:length(fignums)   %#ok<FXUP>
    icon = icon0;                       %reset icon
    icon(X(:,:,k)<175) = uint8(255);    %whiten the filled digit(s)
    j = get(fignums(k),'javaframe');    
    j.setFigureIcon(javax.swing.ImageIcon(im2java(icon)));  %create a java image and set the figure icon
end


end




Contact us at files@mathworks.com