Subplot in loop returns images in separate figures
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (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!