imagesc output: how to re-update the matrix image only, but keep other things intact, including colorbar, axis tick, axis label, annotation, text...?
조회 수: 3 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Stephen23
2025년 3월 15일
편집: Stephen23
2025년 3월 15일
"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
Stephen23
2025년 3월 15일
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');
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Colorbar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!