imagesc output: how to re-update the matrix image only, but keep other things intact, including colorbar, axis tick, axis label, annotation, text...?

6 visualizaciones (últimos 30 días)
Hi, I want to update the imagesc generated figure window, just update the pixel matrix values of same dimension size, but keep other things intact, including cplormap, colorbar, axis tick, axis label, annotation, text,...
But the code below reset and remove everything:
f = figure;
imagesc([1,2,3;4,5,6;]);colorbar;
text(1,2,'apple')
set(gca(f),'YTick', [1,2],'YTickLabel',{'AAA','BBB'},'TickLabelInterpreter','none');
% update the matrxi (of same size) only, but leave the tick labels,text, annotations,...all intact
figure(f)
imagesc([4,5,3;4,7,6;]); % this removes all the tick labels,text, annotations,..
Is there a way to solve this problem? I am using R2016a.
Many thanks for the suggestion.

Respuesta aceptada

Stephen23
Stephen23 el 15 de Mzo. de 2025
Editada: Stephen23 el 15 de Mzo. de 2025
"how to re-update the matrix image only, but keep other things intact, including colorbar, axis tick, axis label, annotation, text...?"
IMAGESC returns an image object. So you can simply update the image object's image CData:
imh = imagesc([1,2,3;4,5,6]);
drawnow % for some reason this does not work on the forum
imh.CData = [4,5,3;4,7,6;];
  1 comentario
Stephen23
Stephen23 el 15 de Mzo. de 2025
Here is a long and convoluted demonstration that works around limitations on this forum:
% Create a tiled layout
tiledlayout(1,2);
% First tile - original image
ax1 = nexttile;
imh = imagesc([1,2,3;4,5,6]);
title('Original Image');
colorbar;
axis image;
% Second tile - copy of the original image
ax2 = nexttile;
copyobj(get(ax1, 'Children'), ax2);
title('Copy of Original');
colorbar;
axis image;
% Now update the CData of the original image - demonstrating the syntax
imh.CData = [4,5,3;4,7,6];
title(ax1, 'After imh.CData update');

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Colorbar en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by