Evenly distribute strings on axis ticks

Hey everyone,
I want to make a graph and replace the 'xticklabel' by an array of strings.
y = rand(20,1); %fake data
bar(y);
XLabelStrings = {'T1', 'T2', 'T3', 'T4', 'T5', 'T6'};
set(gca, 'xticklabel', XLabelStrings, 'xtick', 1:length(XLabelStrings));
I would like to spread the strings evenly over the x axis. However, this array of string doesn't have the same number of values than the number of data points on the graph and i can't seem to find a way to fix this problem.
I have looked around but couldn't find an answer to this particular case.
Thank you for your help!

 採用された回答

Walter Roberson
Walter Roberson 2018 年 2 月 28 日

0 投票

You have 20 data points with implicit x values 1:20. You are requesting xtick 1:6. If you want the first label at 1 and the last at 20 and the other 4 equal in the interior then xtick with linspace(1,length(y), length(XLabelStrings))

1 件のコメント

David Benoit
David Benoit 2018 年 2 月 28 日
Thank you very much. Exactly what i needed.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by