I have been trying to put my graphic axis in log2 scale but something quite odd appears on the figure. The first data 63 appears at the beggining and the end of the x-scale and for some reason the first point does not appear. Also the points are not exactly centered on the x-ticks... do you have any idea why ?
Thanks in advance for you help !!!
clear all; clc;
%% Vectors
freq=[63 125 250 500 1000 2000 4000 8000 16000]
logfreq=log2(freq);
Lp1=[93.9 93.9 93.8 93.8 93.8 93.6 93.3 91.8 87.8]
Lp2=[93.9 93.9 93.8 93.8 94 94.1 94.4 94.6 95.3]
Lp3=[93.9 93.9 93.9 93.8 94.1 94.4 95.2 97.2 100.9]
%% Plot
figure
plot(log2(freq),Lp1,'+-','linewidth',1.7)
hold on; grid on;
plot(log2(freq),Lp2,'+-','linewidth',1.7)
plot(log2(freq),Lp3,'+-','linewidth',1.7)
set(gca,'fontsize',20)
set (gca, 'XTickLabel', logfreq);
set(gca,'XTickLabel',
{'63','125','250','500','1000','2000','4000','8000','16000'})
xlabel('Frequency [Hz]','fontsize',20)
ylabel('Pressure Level [dB]','fontsize',20)
leg=legend({'Sin correcion','Campo libre','Incidencia aleatoria'},'fontsize',18)
And here is the figure :
You want
set(gca,'XTick',logfreq);
instead of set(gca,'XTickLabel',logfreq)
With your incorrect code, the 63 appears at the start and the end because there are (incorrectly) 10 x tick locations but you are specifying only 9 labels, and hence the first one is repeated. (If you'd only specified 8 then the first 2 would be repeated, etc.)