Borrar filtros
Borrar filtros

How do I specify number format in a plot axis in Matlab R2015a?

27 visualizaciones (últimos 30 días)
Matt Brown
Matt Brown el 18 de Oct. de 2017
Editada: Rik el 19 de Oct. de 2017
I have a plot in Matlab R2015a which defaults to having y-axis labels formatted in exponential notation.
As standard practice I like to go in and reformat the axis labels to have consistent precision (which is an unfortunate shortcoming of pre-2016 plots). I do this as follows:
function fixaxislabels( xfrmt,yfrmt )
%fixaxislabels redefines the x and y axis labels to have consistent
% precision IAW xfrmt and yfrmt
xlabel=get(gca,'XTickLabel')
for i=1:numel(xlabel)
xval=str2num(xlabel{i});
xlabel{i}=num2str(xval,xfrmt);
end
ylabel=get(gca,'YTickLabel')
for i=1:numel(ylabel)
yval=str2num(ylabel{i});
ylabel{i}=num2str(yval,yfrmt);
end
xlabel
ylabel
set(gca,'XTickLabel',xlabel);
set(gca,'YTickLabel',ylabel);
However, this only recognizes the actual labels and returns labels between 1.000 and 10.000 rather than 0.001 and 0.010.
How do I force my axis labels to be fixed point notation before I normalize the label precision?

Respuestas (1)

Rik
Rik el 19 de Oct. de 2017
Editada: Rik el 19 de Oct. de 2017
Maybe you should get the actual values, instead of the labels. That would save you a conversion from string to number and solve this problem.
xlabel=get(gca,'XTick');%returns a vector
Edit: you can do this directly by setting the format for your ticklabels. But alas, this function was introduced in R2016b, so your release doesn't have it.
xtickformat(xfrmt)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by