Changing the values on an axis in Matlab 2014b

조회 수: 5 (최근 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 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