Three approaches to selecting a range within a spectogram
Use saveas to save figures as any format. 1. Simple xlim & ylim
A simple approach that will not result in the loss of data would be to set xlim and ylim.
Demo:
x = exp(1j*pi*sin(8*n/N)*32);
spectrogram(x,32,16,64,'centered','yaxis')
title('Full Spectrogram')
rectangle(ax, 'Position', [rectX(1), rectY(1), range(rectX), range(rectY)])
spectrogram(x,32,16,64,'centered','yaxis')
title('Limited range using xlim & ylim')
2. Maintain DataAspectRatio
spectrogram(x,32,16,64,'centered','yaxis')
originalDAR = ax.DataAspectRatio;
ax.DataAspectRatio = originalDAR;
title('Maintain data asepct ratio')
3. Maintain the region's area within the figure
spectrogram(x,32,16,64,'centered','yaxis')
xScale = range(rectX)/range(xl);
yScale = range(rectY)/range(yl);
xShift = (rectX(1)-xl(1))/range(xl);
yShift = (rectY(1)-yl(1))/range(yl);
ax.Position(3) = axPos(3)*xScale;
ax.Position(4) = axPos(4)*yScale;
ax.Position(1) = axPos(1) + xShift;
ax.Position(2) = axPos(2) + yShift;
title('Maintain region''s area within the figure')
Best Answer