MATLAB: Does the PERIODOGRAM function give no output when used with the SUBPLOT function in Signal Processing Toolbox 6.2 (R14)

emptyperiodogramSignal Processing Toolboxsubplot

I have two data sets for which I want periodograms. When I try to plot them in the same figure using SUBPLOT, I obtain two empty axes. I used the following code:
x1=rand(1,100);
x2=rand(1,100);
subplot(2,1,1)
periodogram(x1);
subplot(2,1,2)
periodogram(x2);

Best Answer

This bug has been fixed for Release 14 SP1 (R14SP1). For previous releases, read below for any possible workarounds:
We have verified that there is a bug in Signal Processing Toolbox 6.2 (R14) in the way the PERIODOGRAM function determines which axes to use for plotting.
To work around this issue, use the approach taken in the following code:
x1=rand(1,100);
x2=rand(1,100);
periodogram(x1)
figure
periodogram(x2)
figure(3)
ax = zeros(2,1);
for i = 1:2
ax(i)=subplot(2,1,i);
figure(i)
h = get(gcf,'Children');
h(2:8) = [];
newh = copyobj(h,3)
possub = get(ax(i),'Position');
set(newh(end),'Position',possub)
delete(ax(i));
end
close 1 2
figure(3)
This will plot the two figures as axes in the same figure window. The outcome will be similar to what SUBPLOT usually gives.