Title overwrites previous figure title

22 visualizaciones (últimos 30 días)
Seth Shill
Seth Shill el 26 de Nov. de 2019
Comentada: Rik el 26 de Nov. de 2019
I'm plotting two figures in this short script. I want each figure to have its own title; but for some reason I cannot resolve why the last title is overwriting the title on the previous figure. Please help me answer this. Thanks!
%% Reconstruct Images as Linear Combinations of DCT Bases
close all; clear all; clc;
% Read in grayscale image
I = imread('cameraman.tif');
I = im2double(I);
% Perform a 2-D DCT of the grayscale image using the dct2 function.
Idct = dct2(I);
% Set values less than magnitude 1 or less than 0.5 in the DCT matrix to
% zero for Idct1 and Idct2, respectively.
Idct(abs(Idct) < 0.5) = 0;
Idct1 = Idct;
Idct(abs(Idct) < 1) = 0;
Idct2 = Idct;
% Reconstruct the images using the inverse DCT function idct2.
img = idct2(Idct);
img_1 = idct2(Idct1);
img_2 = idct2(Idct2);
% Display the original grayscale image alongside the processed images.
figure;
imshowpair(img_1,img_2,'montage')
title('Processed Images for DCT Coefficients <0.5 (Left) and <1 (Right)');
figure;
imshow(img);
title('Original Grayscale Image');

Respuesta aceptada

Jakob B. Nielsen
Jakob B. Nielsen el 26 de Nov. de 2019
You call the "title" command, which updates the title of your current figure. Most often, your current figure is the one you most recently plotted something on.
Below is an example. Label your figures, then set the active figure before plotting, labelling etc.
original = figure('Name','Original','NumberTitle','off');
processed = figure('Name','Processed','NumberTitle','off');
%Then, select your "current figure":
figure(original);
plot(x,y)
figure(processed);
plot(x_processed,y_processed)
  1 comentario
Rik
Rik el 26 de Nov. de 2019
It is a better idea to use explicit handles to parent objects, which both the plot and the title functions allow.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by