Filter löschen
Filter löschen

Changing the values on an axis in Matlab 2014b

2 Ansichten (letzte 30 Tage)
Attila Lazar
Attila Lazar am 11 Okt. 2014
Kommentiert: Oleg Komarov am 12 Okt. 2014
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!

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 11 Okt. 2014
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 Kommentar
Oleg Komarov
Oleg Komarov am 12 Okt. 2014
Moved Attila's answer here:
Great! It worked! Many thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by