Filter löschen
Filter löschen

How to hold previous figures when using imagesc?

20 Ansichten (letzte 30 Tage)
Raju Kumar
Raju Kumar am 23 Mai 2023
Bearbeitet: Image Analyst am 29 Mai 2023
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

Antworten (2)

Saffan
Saffan am 29 Mai 2023
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');

Image Analyst
Image Analyst am 29 Mai 2023
Bearbeitet: Image Analyst am 29 Mai 2023
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.

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by