How to hold previous figures when using imagesc?
16 次查看(过去 30 天)
显示 更早的评论
I have many datasets (two of them provided below) to be plotted on a 256x256 pixels image. The first column in each dataset is the pixel index and the second column -intensity. When I am plotting this using 'imagesc', the figure does not update/hold rather only the last dataset gets plotted. Can anyone suggest a code or modify my code below to have all the datasets plotted on a single plot? Many thanks in advance.
Set 1:
26319 2
25806 6
26322 2
25811 7
25295 2
25298 4
26320 8
26321 8
25551 19
25554 18
26063 19
26066 18
25296 9
25297 9
26064 60
26065 61
25552 59
25553 62
25807 49
25810 58
25808 390
25809 378
set 2:
47291 31
47290 7
46269 37
46012 10
47033 34
46010 22
47037 39
47036 129
46011 40
46265 42
46525 94
46268 133
46777 95
46781 95
46267 165
46266 129
46523 238
46522 194
46779 228
46778 195
47035 172
47034 136
46524 194
46521 96
46780 212
The code:
for loop to access each dataset..
H11 = zeros(256,256);
H11(column 1) = column 2;
figure(1)
ax = gca;
imagesc(H11); f1=colorbar; ylabel(f1, 'TOT'); hold(ax, 'on');
colormap(ax, 'jet');
colorbar(ax);
hold(ax, 'on');
xlabel(ax, 'Horizontal pixels');
ylabel(ax, 'Vertical pixels');
end
0 个评论
回答(2 个)
Saffan
2023-5-29
Hi Raju,
imagesc command creates a new plot every time it is called and hence image is overwritten by the last dataset and hold does not work as expected. You need to create a running sum of all the datasets in each iteration and then plot the sum after the loop.
Here is an example code snippet:
H_sum = zeros(256,256);
for loop to access each dataset..
H11 = zeros(256,256);
H11(column 1) = column 2;
% creating a running sum
H_sum = H_sum + H11;
end
figure(1)
ax = gca;
imagesc(H_sum);
f1=colorbar;
ylabel(f1, 'TOT'); hold(ax, 'on');
colormap(ax, 'jet');
colorbar(ax);
hold(ax, 'on');
xlabel(ax, 'Horizontal pixels');
ylabel(ax, 'Vertical pixels');
0 个评论
Image Analyst
2023-5-29
编辑:Image Analyst
2023-5-29
If you want to paste an opaque copy of the newest image on top of existing images, see my attached copy and paste demo.
If you want plots inset to an image, see attached demos.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!