% function changeloglabels(haxes)
%
% PURPOSE: Function changes the log labels of 10^XX to linear units. For
% example from 10^1.45 to 28.18. Recalculates and displays when zoom
% in/out and pan are used.
%
% USE: Can be used from command line or inside display functions, simply
% send the handles of the axes that you wish the function to operate on.
% Function will determine which axes or both are log.
%
% Jeffrey A Ballard
% January 15, 2009
function changeloglabels(haxes)
% Get the figure handles for each of the figures, and determine which axes
% belong to which figure
for ii=1:length(haxes)
hfig(ii) = get(haxes(ii),'Parent');
end
figs = unique(hfig);
for ii=1:length(figs)
ind_haxes{ii} = find(hfig==figs(ii));
end
% Now loop over one figure at a time, then each axes on the figure
% 1. create random tags for the axes
% 2. change the labels to linear units
% 3. set the zoom in/out, pan functions using the random tags
for jj=1:length(figs)
for ii=1:length(ind_haxes{jj})
% Creating random tags
char1 = char(floor(rand*25)+97);
char2 = char(floor(rand*25)+97);
char3 = char(floor(rand*25)+97);
char4 = char(floor(rand*25)+97);
char5 = char(floor(rand*25)+97);
tags{ii} = [char1 char2 char3 char4 char5 '_' num2str(round(rand*1000000))];
% Change the labels to linear units
set(haxes(ind_haxes{jj}(ii)),'Tag',tags{ii})
if strcmpi(get(haxes(ind_haxes{jj}(ii)),'XScale'),'log')
set(haxes(ind_haxes{jj}(ii)),'XTickLabelMode','auto')
xlabels = get(haxes(ind_haxes{jj}(ii)),'XTickLabel');
for mm=1:size(xlabels,1)
xticklabels{mm}=num2str(10^(str2double(strtrim(xlabels(mm,:)))));
end
set(haxes(ind_haxes{jj}(ii)),'XTickLabel',xticklabels)
clear xticklabels
end
if strcmpi(get(haxes(ind_haxes{jj}(ii)),'YScale'),'log')
set(haxes(ind_haxes{jj}(ii)),'YTickLabelMode','auto')
ylabels = get(haxes(ind_haxes{jj}(ii)),'YTickLabel');
for mm=1:size(ylabels,1)
yticklabels{mm}=num2str(10^(str2double(strtrim(ylabels(mm,:)))));
end
set(haxes(ind_haxes{jj}(ii)),'YTickLabel',yticklabels)
clear yticklabels
end
end
% Create the string that identifies the tags for callbacks
start = ['tags{1}=''' tags{1} ''''];
for ii=2:length(ind_haxes{jj})
start = [start ';tags{' num2str(ii) '}=''' tags{ii} ''''];
end
% Get the zoom and pan handles
hzoom = zoom(figs(jj));
hpan = pan(figs(jj));
% Set the callbacks to remake the labels
set(hzoom,'ActionPostCallback',...
sprintf([ start ';for ii=1:length(tags);hax = findobj(%d,''Tag'',tags{ii});if strcmp(get(hax,''XScale''),''log'');set(hax,''XTickLabelMode'',''auto'');xlabels = get(hax,''XTickLabel'');for jj=1:size(xlabels,1);xticklabels{jj}=num2str(10^(str2double(strtrim(xlabels(jj,:)))));end;set(hax,''XTickLabel'',xticklabels);end;if strcmp(get(hax,''YScale''),''log'');set(hax,''YTickLabelMode'',''auto'');ylabels = get(hax,''YTickLabel'');for jj=1:size(ylabels,1);yticklabels{jj}=num2str(10^(str2double(strtrim(ylabels(jj,:)))));end;set(hax,''YTickLabel'',yticklabels);end;end'],figs(jj)));
set(hpan,'ActionPostCallback',...
sprintf([ start ';for ii=1:length(tags);hax = findobj(%d,''Tag'',tags{ii});if strcmp(get(hax,''XScale''),''log'');set(hax,''XTickLabelMode'',''auto'');xlabels = get(hax,''XTickLabel'');for jj=1:size(xlabels,1);xticklabels{jj}=num2str(10^(str2double(strtrim(xlabels(jj,:)))));end;set(hax,''XTickLabel'',xticklabels);end;if strcmp(get(hax,''YScale''),''log'');set(hax,''YTickLabelMode'',''auto'');ylabels = get(hax,''YTickLabel'');for jj=1:size(ylabels,1);yticklabels{jj}=num2str(10^(str2double(strtrim(ylabels(jj,:)))));end;set(hax,''YTickLabel'',yticklabels);end;end'],figs(jj)));
% Clear variables
clear start tags
end
end