フィルターのクリア

Changing the values on an axis in Matlab 2014b

2 ビュー (過去 30 日間)
Attila Lazar
Attila Lazar 2014 年 10 月 11 日
コメント済み: Oleg Komarov 2014 年 10 月 12 日
I have recently installed Matlab 2014b and some of my earlier graph formatting code does not work anymore. I have several graphs in programmatic gui and when I have a large number to plot, e.g. 15000, the program automatically displays it on the y-axis as 1.14x10^4. I would like to display the y-axis values as 11400 or 11,400. This code used to work with Matlab 2014a:
ax1=handles.fig_results;
plot(x1m, y1, x1m, y2, 'parent', ax1);
hleg1 = legend('Male population','Female population', 'Location','SouthWest');
xlabel('years', 'FontSize',12,'FontWeight','bold','parent', ax1);
ylabel('No of individuals', 'FontSize',14,'FontWeight','bold','parent', ax1);
yt = get(ax1,'YTick'); % change the tickmark format
set(ax1,'YTickLabel', sprintf('%.0f|',yt));
When I run this code in Matlab 2014b, now, all the y-tick values are the same: 11000|11100|11200|11300|11400
Is there a way to fix this? Thanks!

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 10 月 11 日
Attila - looking at the documentation for changing tick labels of graph, the YTickLabel (and XTickLabel) can (should?) be set with a cell array of strings. (In the past, I would have done something similar to you and just passed a string.)
So try converting your string of numbers into a cell array. Since you are suffixing each number with the pipe character, then you should be able to do the following
set(ax1,'YTickLabel', strsplit(sprintf('%.0f|',yt),'|'));
Here we are using strsplit to split the string at the | delimiter.
  1 件のコメント
Oleg Komarov
Oleg Komarov 2014 年 10 月 12 日
Moved Attila's answer here:
Great! It worked! Many thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by