P-Gn
P-Gn

Reputation: 24581

Missing axes in figure with multiple subplots

I am drawing a figure with multiple subplots with the following code

w = 7;
h = 5;

figure;
m = 0.005;
for n = 1:w*h
  [I, J] = ind2sub([w, h], n);
  pos = [(I-1)/w+m, (J-1)/h+m, 1/w-2*m, 1/h-2*m];
  h_axes = subplot(h, w, n, 'position', pos);
  imagesc(rand(10), 'Parent', h_axes);
  axis(h_axes, 'image')
  axis(h_axes, 'off')
end

However, only the top two rows are plotted, whereas 5 rows are expected. Going through this code step by step, it seems that lower rows are initially drawn but later upper rows erase them. The axes handles are invalidated, so the axes are not simply hidden but really deleted. Any idea what is going on?

Upvotes: 0

Views: 76

Answers (1)

LowPolyCorgi
LowPolyCorgi

Reputation: 5171

There is a problem with the way you use subplot. You can use either syntax:

subplot(m,n,p)

or

subplot('Position',positionVector)

... but not both in the same call.

Upvotes: 1

Related Questions