Search code examples
matlabgeospatialaxis-labels

Programmatically add letters to axis labels in Matlab


I'm using Matlab R2016a. I'd like to take the current axis labels and append a string on to the end of each label, programmatically without manual editing.

To be clear, my current axis labels are:

115, 116, 117, 118

And I'd like to automatically add an E after each label, so that the labels are:

115E, 116E, 117E, 118E

I've tested getting the current axis labels and converting them to a cell, in an effort to concatenate a string on to the end of them, but I couldn't get it to work. Any help would be greatly appreciated.

Edit: Oh and I'd prefer to achieve it without an additional function (i.e. from File Exchange)... if possible.


Solution

  • labels = get(gca, 'XTicklabels');    % get current labels as a cell array of strings
    labels_new = strcat(labels, 'E');    % postpend 'E' to each label
    set(gca, 'XTicklabels', labels_new)  % set as new labels