Changing the values on an axis in Matlab 2014b

2 次查看(过去 30 天)
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by