Issues with labelling bar graph along the x axis?

10 ビュー (過去 30 日間)
Bethany Sinclair
Bethany Sinclair 2021 年 1 月 24 日
編集済み: Bethany Sinclair 2021 年 1 月 26 日
Hi,
I don't want the numbers along the bottom to be 1-10, rather a min and max value inputted in the command window and then the values in between determined by an interval also specificed in the command window
  2 件のコメント
Adam Danz
Adam Danz 2021 年 1 月 24 日
編集済み: Adam Danz 2021 年 1 月 24 日
So what if someone enters 100, 1000, 2 which would produced 451 values?
What's the problem with setting the xticklabel of the axis?
Adam Danz
Adam Danz 2021 年 1 月 24 日
編集済み: Adam Danz 2021 年 1 月 24 日
The input() function is rarely a good idea and is wildely unconstrained. See my anser on how to define xticklabels as a numeric vector.
Reasons why input() isn't safe and alternatives:
Testing user input and reprompting user if their input doesn't make sense:

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

採用された回答

Adam Danz
Adam Danz 2021 年 1 月 24 日
This shows how to convert a numeric vector to x tick labels.
It includes an assertion that will throw an error if the number of x tick labels does not match the number of x ticks.
The number of decimal places in the labels is set to 0 and can be changed in the '%.0f' format command.
data = rand(10,3);
ax = gca();
bar(ax, data, 'stacked')
newXTicks = 100:10:190; % Numeric vector of XTickLabels
assert(numel(ax.XTick)==numel(newXTicks), 'Number of XTickLabels does not match number of XTicks.')
ax.XTickLabels = compose('%.0f', newXTicks);
  1 件のコメント
Bethany Sinclair
Bethany Sinclair 2021 年 1 月 25 日
Amazing - thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by