Merge two separate figures into one
5 次查看(过去 30 天)
显示 更早的评论
In the attached code, I use two separate figure windows.
But how could I bring them under "one" figure?
I guess I have to use subplot() but I'm not sure how to go about it....
Any help is appreciated. This is how my application works : I open up an image in one window and show its projected colors onto a CIE ab diagram. When the user clicks on the image, it draws a circle on the second window. I have not found how to delete the freshly drawn circles between each clicks of the mouse (or do I have to worry about that at all?)
4 个评论
Simon Chan
2022-2-5
As mentioned by others, there are different ways to achieve the same target.
The attached modified code uses 2 uipanels on one figure.
Noticed that I didn't perform comprehesive tesing on it and some of the items may have positions different from yours.
You may modify again according to your needs.
回答(1 个)
Abhishek Chakram
2023-10-3
Hi Roger Breton.
It is my understanding that you want to merge multiple figure windows. Here’s a sample code for that:
[fileNames, filePath] = uigetfile('*.jpg', 'Select JPG files', 'MultiSelect', 'on');
% Check if the selected files are returned as a cell array
if iscell(fileNames)
numFiles = numel(fileNames);
else
numFiles = 1;
fileNames = {fileNames};
end
% Calculate the number of rows and columns for the subplot
numRows = ceil(sqrt(numFiles));
numCols = ceil(numFiles / numRows);
figure;
for i = 1:numFiles
% Construct the full file path
fullFilePath = fullfile(filePath, fileNames{i});
image = imread(fullFilePath);
subplot(numRows, numCols, i);
imshow(image);
% Set the title of the subplot to the corresponding file name
title(fileNames{i});
end
In this example, uigetfile allows the user to select multiple images at a time which is then displayed all together in a single figure window using subplot.
You can refer to the following documentation to know more about the functions used:
- subplot: https://www.mathworks.com/help/matlab/ref/subplot.html
- imshow : https://www.mathworks.com/help/images/ref/imshow.html
- imread : https://www.mathworks.com/help/matlab/ref/imread.html
- fullfile : https://www.mathworks.com/help/matlab/ref/fullfile.html
- uigetfile : https://www.mathworks.com/help/matlab/ref/uigetfile.html
Best Regards,
Abhishek Chakram
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!