MATLAB: How to plot non equally spaced data in an equally spaced fashion.

gridplotsxticks

I am trying to plot some data:
x=[10 50 100 500 1000 1500 2000 2500 3000]; %data points
y=[74.6 88.8 89.6 92.1 92.5 88.8 88.8 87.9 85.4]; %accuracy(%)
The problem I am facing is that I cannot plot the data in an equally-spaced grid plot (including the tick locations). This is an example of what I want to achieve:
Thanks for your help in advance. Raul

Best Answer

See if this does what you want:
x=[10 50 100 500 1000 1500 2000 2500 3000]; %data points

y=[74.6 88.8 89.6 92.1 92.5 88.8 88.8 87.9 85.4]; %accuracy(%)

xt = [10 50 100 500 1000 1500 2000 2500 3000 3500];
xv = 1:length(xt);
yv = interp1(x, y, xt, 'linear', 'extrap'); % Extrapolate The ‘3500’ Value
figure(1)
plot(xv, yv) % Plot Interpolated Values Against ‘xv’

grid
set(gca, 'XTickLabel',xt) % Label Ticks As ‘xt’

ylabel('Accuracy (%)')
If you do not want to extrapolate to 3500, the code would be:
x=[10 50 100 500 1000 1500 2000 2500 3000]; %data points
y=[74.6 88.8 89.6 92.1 92.5 88.8 88.8 87.9 85.4]; %accuracy(%)
xv = 1:length(x);
figure(1)
plot(xv, y) % Plot Interpolated Values Against ‘xv’
grid
set(gca, 'XTickLabel',x) % Label Ticks As ‘xt’
ylabel('Accuracy (%)')