Reputation: 3346
I'm trying to iterate over my cell
array and sub-plot each image that's stored there.
See my code:
for i=1:96
for j=1:9
subplot(ceil(sqrt(960)),ceil(sqrt(960)),i)
imshow(trainingData{2}{i}{j})
end
end
I have 96 cells (in i
column) that each contain 10 images (j
column) (of which the first 9 I want to plot).
I know it's pretty pointless because they're so small, but I've started it and seems I can't get it working how I thought, I'd really like to know where I'm going wrong before I just drop it. (also the program may have less images in the future anyway).
So far, it's only sub-ploting 96 entries; it should be 864:
In case my data structure confuses you, here's a little explanation:
trainingData
is a Mat file which I load, the first column needs a 1 if you want to access a persons name, or a 2 if you want to their images. The second column contains 96 people (from 1 to 96. The third column is 10 pictures of the person.
eg. trainingData{2}{56}{7} accesses the 56th persons 7th photo.
I'm sure many will see this as an unorthodox data structure, but that's how I thought of doing it at the time. Thanks.
Upvotes: 0
Views: 209
Reputation: 112769
The problem seems to be the line
subplot(ceil(sqrt(960)),ceil(sqrt(960)),i)
which causes the 9 images in the inner loop to be overwritten in the same subplot (so only the last one is seen). Change it to
subplot(ceil(sqrt(960)),ceil(sqrt(960)),(i-1)*9+j)
so that all subplots are used.
Upvotes: 2