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.

 

Advertisements

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s