MATLAB: Add secondary semilogx axis to linear plots

MATLABplot

First off, I'm new to matlab, so sorry for ugly codes and maybe an easy question. Anyway, I would like to add a secondary -log2 X axis on top to an existing histogram and curve with linear axes. It will be the same curve, but different units, so I really only need to adjust the top scale to -log base 2 units. I tried using: 'xscale','log' in ax3, but I'm not sure how to change the base?
figure
bar(size_phi, vol_percent,'LineWidth',0.05,'EdgeColor',[0.6 0.6 0.6],'FaceColor',[0.42 0.42 0.42]);
ax1 = gca;
set(gca, 'box','off');
ax1.XColor = 'k';
ax1.YColor = [0.4 0.4 0.4];
ax1.YAxisLocation = 'right';
ax1.XLim = [-2 15];
ax1.TickDir = 'out';
ax1.XLabel.String = 'Size (\phi)';
ax1.YLabel.String = {'Volume (%)'; 'histogram'};
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,'box','off','YAxisLocation','left','XTickLabel',[],'Color','none','TickDir','out','XLim',[-2 15],'YLim',[0 100]);
hold on
plot(GStablePlot.size_phi,GStablePlot.vol_cumulative,'Color',[0 0 0],'LineWidth',2);
ax3 = axes('Position',ax1_pos,'box','off','YAxisLocation','left','YTickLabel',[],'Color','none','TickDir','out','YLim',[0 100],'XAxisLocation','top','XDir','reverse');
hold on
semilogx(log2(GStablePlot.size_mm),GStablePlot.vol_cumulative);

Best Answer

OK, I think this is close if I understood correctly...
% make up some dummy data that sorta' looks similar...
phi=-2:2:14; % phi values x
mm=2.^-phi; % mm lengths associated
x=-3:0.01:3; % a big number
y=random('normal',6,1,size(x)); % build a distribution
[cf,xcf]=ecdf(y); % and the cumulative to go with it
mcf=2.^-xcf; % but convert to length units on x
[n,c]=hist(y,100); % group to make a bar plot
F=2.75/max(n); % arbitrary scale to match appearances
% OK, here's where the meat begins...
% First draw basic plot of cdf and bar on left, right axes saving handles
[hAx,hL1,hL2]=plotyy(mcf,cf*100,c,n*F,@plot,@bar);
% now a bunch of fixups...
set(hAx,{'xlim'},{[-2 15]}) % set bot x-axis limits so know where are
set(hAx(1),'XAxisLocation','top', 'XDir','reverse') % position LH at top, reverse
% must set limits and tick values in ascending order irregardless, ML is too picky
set(hAx(1),'XLim',sort(2.^-hAx(1).XLim),'XTick',sort(mm),'XScale','log')
hAx(1).YTick=[0:10:100]; % make ticks match what want
hAx(2).XAxis.Visible='on'; % plotyy makes only one x-axis visible by default
set(hAx(2),'YLim',[0 3]) % adjust range to match sample
hAx(2).YTick=[0:0.5:3]; % and ticks
hAx(2).YAxis.TickLabelFormat='%0.1f'; % and fixup the ugly default formatting
set(hL1,'LineWidth',2,'color','k') % and touch up the line characteristics
ADDENDUM
I just noticed the effect of the 'EdgeColor' owing to so many bars; this can be fixed if it's issue in yours via
hL2.EdgeColor=hL2.FaceColor;
and, of course, can set 'FaceColor' as desired besides just default.