MATLAB: How to have a graph with labeled x-axis ticks on the bottom and top of the graph

axesaxishorizontallabel;locationMATLABtickxaxislocationxtickxticklabel

I would like to make a graph which has labeled tick marks along the bottom and top of the graph. The tick marks should be in the same horizontal positions, but with different labels. How can I do this?

Best Answer

By default the plot should have a set of axes with a labeled set of tick marks on the bottom and the left. The example below explains how this can be done for both the X and Y axes with different Tick labels on all four sides.
plot(1:10);
% First, store the handle to those axes.
% Next create a second set of axes,
% position This on top of the first and make it transparent.
ax1=gca;
ax2 = axes('Position', get(ax1, 'Position'),'Color', 'none');
set(ax2, 'XAxisLocation', 'top','YAxisLocation','Right');
% set the same Limits and Ticks on ax2 as on ax1;
set(ax2, 'XLim', get(ax1, 'XLim'),'YLim', get(ax1, 'YLim'));
set(ax2, 'XTick', get(ax1, 'XTick'), 'YTick', get(ax1, 'YTick'));
OppTickLabels = {'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k'}
% Set the x-tick and y-tick labels for the second axes
set(ax2, 'XTickLabel', OppTickLabels,'YTickLabel',OppTickLabels);