I have three suggestions that might work for you:
1. Reconsider your stance on the issue at hand. Are you really sure that the first plot is correct? According to the documentation,
"surf(Z) creates a three-dimensional shaded surface from the z components in matrix Z, using x = 1:n and y = 1:m, where [m,n] = size(Z). The height, Z, is a single-valued function defined over a geometrically rectangular grid."
Note that the default X-Y grid here is in linear scale and the default X-Y data points themselves are linear.However, in the real scenario, a grid created with the ACTUAL X-Y data, may have data points scattered non-linearly in a linearly scaled graph. Here is an example to demonstrate what I mean:
x = [1:10].^3;
y = rand(10,1);
plot(y)
figure
plot(x,y)
Notice figure 2 contains a stretched version of the plot in figure 1. However, figure 2 actually contains the correct plot! The plot in figure 2 got stretched because the actual x-data points are non-linearly spaced.
I have a feeling this explanation is applicable to your case too.
2. Generate the first plot and capture the plot box aspect ratio in a variable.
% Generate first plot
pbr = get(gca,'PlotBoxAspectRatio')
%Close this plot and generate the second plot
%Now set the plot box ratio to pbr
set(gca,'PlotBoxAspectRatio',pbr)
3. If the above suggestion does not help, you can manually overwrite the tick labels in your first plot, with the required values. For example, to overwrite the values of the X-axis ticks with 'spec' values, try the following:
%Generate the first plot , make sure the variables spec etc exist in the workspace
%Get current figure axes handle
axesHandle = gca;
%Get current BIN tick values
CurrentTicks = axesHandle.XTick;
bins = 1:length(spec);
p = polyfit(bins,spec,1);
NewTicks = polyval(p,CurrentTicks);
%Reset the tick values
axesHandle.XTickLabel = NewTicks;
%Change the tick label mode to manual to prevent resize changes
axesHandle.XTickMode = 'manual'
axesHandle.XTickLabelMode = 'manual'