Matlab: Putting labels on plot axis

I can’t just plot the X-axis with strings and expect the Matlab plot function to do what it is supposed to do (Which is label each X point with the string). The work around for this inconvenience is to use the XTick and XTickLabel. Found this useful stack overflow article that explains it all :)

x = 1:5;
y = rand(size(x));
plot(x, y, 'b')
set(gca, 'XTick',1:5, 'XTickLabel',{'A' 'B' 'C' 'D' 'E'})

Use the XTick to signal how many X axis elements there are. And use XTickLabel to signal the labels for each X axis element. In my case I only used XTickLabel.

 

Unknown's avatar

About joelgranados

I'm fascinated with how technology and science impact our reality and am drawn to leverage them in order to increase the potential of human activity.
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a comment