To display the labels on the axes in the desired format, use the following code (for non floating point numbers)
function s = formatinput1(n)
num = n;
s = cell(1,numel(n));
for i = 1:numel(num)
str = strtrim(num2str(num(i)));
if length(str) < 3
if length(str) == 1
strnew = strtrim('00');
strreq = strcat(strnew,str);
s{i} = strreq;
end
if length(str) == 2
strnew = strtrim('0');
strreq = strcat(strnew,str);
s{i} = strreq;
end
else
strreq = str;
s{i} = strreq;
end
end
end
s is a cell array returned by the function that contains the labels in the desired format, which can be used in conjunction with the XTickLabel property of the set function.
For floating point numbers, call the following function for each floating point number that is to be converted to the desired format.
function newstr = formatinput2(n)
str = strtrim(num2str(n));
[num1,num2] = strtok(str,'.');
ns = formatinput1(str2num(num1));
newstr = strcat(strtrim(ns),strtrim(num2));
end
Best Answer