How to remove some xticklabels (but still keeping all the xticks)?

How can I remove some xticklabels, but still keeping all the xticks?
Let's consider the following example:
x = 1:100;
y = exp(-0.1*x);
plot(x,y)
I want to remove the xticklabels corresponding to "0", "10", "20", "30", getting the following plot:
How can I do it?
I tried the following, without success:
ax = gca;
ax.XTickLabel(1:4) = '';

 採用された回答

Voss
Voss 2024 年 10 月 29 日
x = 1:100;
y = exp(-0.1*x);
plot(x,y)
ax = gca;
ax.XTick = 0:10:100;
ax.XTickLabels(1:4) = {''};

その他の回答 (1 件)

Steven Lord
Steven Lord 2024 年 10 月 29 日

1 投票

x = 1:100;
y = exp(-0.1*x);
plot(x,y)
xticks(0:10:100)
xl = xticklabels;
xl(1:2:end) = {''}; % Replace every other label
xticklabels(xl)

カテゴリ

質問済み:

Sim
2024 年 10 月 29 日

コメント済み:

Sim
2024 年 10 月 29 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by