In your code, window is length 300+1000 = 1300
In your while loop, i:i+length(window)-1 would be length(window) = 1300 long, so xw will be 1300 entries, so spectrogram(:,j) would end up with 1300 rows (same as you initialize it to be.)
In your code, N = length(x) which would typically be the number of samples, but could be the number of channels instead of the number of samples was fewer than the number of channels (it could happen.)
fVec is created from 0:N-1 so fVec is N long -- number of samples.
You plot(Fvec, 20*log10(spectrogram(:,j)) . We demonstrated above that Fvec is the full number of samples in the sound. But spectrogram(:,j) we demonstrated with be the size of the window, 1300. That is a mismatch unless the sound just happens to be exactly 1300 samples long.
Perhaps your Fvec should be created based upon the window size.
