MATLAB: How to insert a colorcloud into a subplot

color thresholdercolorcloudImage Processing ToolboxMATLAB

Hi there,
I was wondering how can I add a colorcloud graph into a subplot. I see that kind of graph in the Image Processing Toolbox / Color Thresholder app.
Here is the code that I use to insert different Images and graph into a figure:
Titles are not in the right position. Also the third plot overlape the 5th and sometimes make the 3rd in half size.
I appreciate your help.
RGB = imread('peppers.png');
grayImage = rgb2gray(RGB);
subplot(3, 3, 1);
imshow(RGB);
% Maximize the figure window.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Force it to display RIGHT NOW
drawnow;
caption = sprintf('Title 1');
title(caption, 'FontSize', 10);
axis image;
subplot(3, 3, 2);
imshow(grayImage);
drawnow;
caption = sprintf('Title 2');
title(caption, 'FontSize', 10);
axis image;
%hpanel = subplot(3, 3, 3);
hpanel = uipanel('Parent',gcf,'Position', [0.6, 0.6, 0.4, 0.4],'Tag','ui');
colorcloud(RGB,'rgb','Parent',hpanel);
drawnow;
title('Title 3', 'FontSize', 10);
subplot(3, 3, 4);
imshow(grayImage)
title('Title 4', 'FontSize', 10);
[pixelCount, grayLevels] = imhist(grayImage);
subplot(3, 3, 5);
bar(pixelCount);
title('Title 5', 'FontSize', 10);
xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;

Best Answer

I'd probably set up all the plots, then add the uipanel last.
figure;
% Maximize the figure window.
set(gcf,'Visible','on','units','normalized','outerposition',[0 0 1 1])
RGB = imread('peppers.png');
grayImage = rgb2gray(RGB);
subplot(3, 3, 1);
imshow(RGB);
title('Title 1', 'FontSize', 10);
axis image;
subplot(3, 3, 2);
imshow(grayImage);
title('Title 2', 'FontSize', 10);
axis image;
subplot(3, 3, 3)
title('Title 3', 'FontSize', 10);
axis off
subplot(3, 3, 4);
imshow(grayImage)
title('Title 4', 'FontSize', 10);
[pixelCount, grayLevels] = imhist(grayImage);
subplot(3, 3, 5);
bar(pixelCount);
title('Title 5', 'FontSize', 10);
xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;
% Add uipanel last
hpanel = uipanel('Parent',gcf,'Position', [0.67, 0.7, 0.25, 0.2]);
colorcloud(RGB,'rgb','OrientationAxesColor','none','Parent',hpanel);