필터 지우기
필터 지우기

Subplot in loop returns images in separate figures

조회 수: 1 (최근 30일)
Paul Costache
Paul Costache 2021년 8월 16일
답변: Walter Roberson 2021년 8월 16일
Hello.
I am running this loop and I want to save the results after each loop and show them in the same subplot, but I get for example in this case 4 different figures with the corresponding image. I would like to get only one figure with the 4 subplots. Thanks for your help!
n=4;
nrows = n/2; % number of subplot rows f. subplot mit alle maskedRGBImage
ncols = n/2; % number of subplot columns
nsubs = nrows * ncols; % total number of subplots
for f = 1:n
f4=figure('Name','Bilder vor und nach Bearbeitung');
hold(subplot(nrows, ncols,f), 'on');
subplot(nrows, ncols, f)
imshow(maskedRGBImage);
%this part shows the object idx on top of the object
textFontSize2 = 8; % Used to control size of "particle number" labels put atop the image.
labelShiftX = -140 ; % Used to align the labels in the centers of the objects.
allBlobCentroids = [stats2.Centroid];
centroidsX = allBlobCentroids(1:2:end-1);
centroidsY = allBlobCentroids(2:2:end);
% Index in Mitte der Partikel anzeigen; top to bottom, left to right
for k = 1 : numberOfparticles % Loop through all particles.
text(centroidsX(k) + labelShiftX, centroidsY(k), num2str(k), 'FontSize', textFontSize2, 'FontWeight', 'Bold','Color','red');
end
%
title(['Masked Image' num2str(f)]);
drawnow;
end

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 16일
f4=figure('Name','Bilder vor und nach Bearbeitung');
However, figure(f) and figure(n) are the only two syntaxes that return existing figures. When you pass in any parameter other than f (a figure handle) or n (an integer figure number) then it is either an error or else a new figure is created.
If you are trying to retrieve an existing figure, then record f4 before the for loop, and if necessary then
figure(f4)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by