I have a figure that displays 20,000 points on the x-axis. So it labels the x-axis from 0 ... 20,000. However, now I would like to scale it from 0 to 50. But when I try to do this in the plot window it just shows me the first 50 points, instead of changing the scale. Is there any straightforward way to do that in MATLAB?
When you change the axis scale in the plot window, you are simply changing the view on the same data. What you need to do is change the x-values of the points themselves.
I think that to do that you can use a vector of linspace(0, 50, 20000)
as your x-coordinates in your plot
command to give you a set of points with x values in the range of 0 to 50, but you'd need to show the commands you're currently using to generate your plot for me to give you a more detailed answer.
You have to change the x-values in your plot, or you can change the axis labels.
Here is how you plot using specific x-values:
%# create some data
data = randn(20000,1);
%# create 20,000 corresponding x-values so that the last one is 50 - works for any number of data points
x = linspace(1,50,length(data));
%# plot
plot(x,data)
EDIT Doresoom has conveniently shown how to change the axis labels.
Try using the xticklabel
axes property.
set(gca,'XTickLabel',{'0';'10';'20';'30';'40';'50'})
should give you what you want.
EDIT:
Careful with messing with tick labels instead of actually modifying the data, though. If you have more ticks than labels, MATLAB will start repeating your tick mark array. You can take care of that by making sure the ticks and labels are equal in length first:
set(gca,'XTick',[0:4000:20000])