Search code examples
matlabmatlab-figure

How can I specify the value of X Label in Matlab figure


I have a matlab figure, where the X and Y vectors are as below:

X = [4 8 16 32 64 128 256 512 1024]; 
Y = [1   1.5   2 2.5    3    3    4    4    5]; 
plot(X, Y, 'b-p','LineWidth',1.0);hold on   %

The figure is shown as following:

enter image description here

My concern, can I shown the X_label with specific values, for example I want the X label to be similar to X, which is [4 8 16 32 64 128 256 512 1024]; similar to the below example:

enter image description here

When using the function xticks or xticklabels, that becomes as below:

enter image description here

However, what I wants is to have equal distance as the figure shown before.


Solution

  • Your x-axis is exponential, so what you want is semilogx with xticks like this:

    X = [4 8 16 32 64 128 256 512 1024]; 
    Y = [1   1.5   2 2.5    3    3    4    4    5]; 
    semilogx(X, Y, 'b-p','LineWidth',1.0)
    xticks(X);
    axis tight
    grid on
    

    enter image description here