简体   繁体   中英

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:

在此处输入图像描述

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:

在此处输入图像描述

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

在此处输入图像描述

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

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM