1

I have a double loop where I wish to also return a subplot:

for j = 1:tileno 
    for k = 1:tileno 

    imsub{j,k} = imgquant(rowdiv*(j-1)+1:rowdiv*j, coldiv*(k-1)+1:coldiv*k);
    subplot(tileno, tileno, ???); hist(imsub{j,k}(:), n_bins);

    end 
end

So the code stores some rowdiv*coldiv images in imsub{j,k} and during that loop I wish to plot a histogram of each of these stored images. I tried running a loop over that double loop:

for j = 1:tileno 
    for k = 1:tileno 
        for p = 1:tileno^2

    imsub{j,k} = imgquant(rowdiv*(j-1)+1:rowdiv*j, coldiv*(k-1)+1:coldiv*k);
    subplot(tileno, tileno, p); hist(imsub{j,k}(:), n_bins);

        end 
    end
end

but this returned the same histogram tileno^2 times, so I think it does a histogram of imsub{1,1} for instance and then subplots this for each p, rather than for each p returning a distinct hist(imsub{j,k}). Many thanks for any help.

1
  • Actually I just noticed I can do subplot(tileno, tileno, tileno*(j-1)+k) and that gives a unique index for each subplot. Commented Jun 8, 2015 at 16:11

1 Answer 1

1

You need to compute the index manually:

for j = 1:tileno 
    for k = 1:tileno 
    plot_index = (j-1)*tileno+k;
    imsub{j,k} = imgquant(rowdiv*(j-1)+1:rowdiv*j, coldiv*(k-1)+1:coldiv*k);
    subplot(tileno, tileno, plot_index hist(imsub{j,k}(:), n_bins);

    end 
end
Sign up to request clarification or add additional context in comments.

1 Comment

Spotted that just before your answer! Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.