Select a different base for a logarithmic plot in matlab

Viewed 30961

I want to have the x-axis logarithmic to the base 2: From 2^10 to 2^25 and at each step the exponent should increase by one, while the y-axis should be linear.

How is this possible? I already figured out

set(gca,'XScale','log')

but u can't set the base.

5 Answers

The simplest way is

x = 2.^(0:10);
y = log2(x);
plot(log2(x), y)       
set (gca, 'XTickLabel', strcat('2^{',num2str(log2(x(:))),'}'));  % or
set (gca, 'XTickLabel', strcat('$2^{',num2str(log2(x(:))),'}$'));% forlatex interpreter

enter image description here

Related