Hello,
I have search a solution for my problem but didn't find any that suited my problem.
Basically, I have a 3D matrix (18x17x2000) representing heatmap of a sample on the 2000 frames of the measurement. I would like to plot it all but with a slider or a cursor or whatever that could allow me to chose which frame I want to display, allowing me to easily go through my data.
I tried the VideoWriter tool but it gives really blurry and not convenient result. The goal is to keep the heatmap representation.
Thank you for your help,

 채택된 답변

Adam Danz
Adam Danz 2022년 9월 27일
편집: Adam Danz 2022년 9월 28일

2 개 추천

This demo produces a heatmap with random data and a slider that controls which slice of the 3rd dimension of data to plot.
Demo based on a similar solution for bar plots but uses a ValueChangingFcn to update the heatmap and title as the slider changes instead of a ValueChangedFcn which is evoked after making a change to the slider.
data = rand(20,20,2000); % data with size n*m*k
fig = uifigure();
uip = uipanel(fig,'Position', [20 100 500 300]);
heatObj = heatmap(uip, data(:,:,1));
title(heatObj, 'Frame #1');
n = size(data,3);
uis = uislider(fig,'Position',[50 50 450 3],...
'Value',1, ...
'Limits', [1,n], ...
'MajorTicks', [1, 200:200:n], ...
'MinorTicks', []);
uis.ValueChangingFcn = {@sliderChangingFcn, data, heatObj};
function sliderChangingFcn(~,event,data,heatObj)
% Update heatmap and title with new selection of data
value = round(event.Value);
heatObj.ColorData = data(:,:,value);
heatObj.Title = sprintf('Frame #%d',value);
end
Tip: set clim so the colorbar limits do not jump around as the heatmap data are updated. This is seen in the GIF below.

댓글 수: 8

Julien Maxime
Julien Maxime 2022년 9월 27일
It is exactly what I needed, thank you very much. Hoping this can help others with the same issue as mine.
Julien Maxime
Julien Maxime 2022년 9월 27일
I have another related question. Do you think it is possible to make the heatmap change as the cursors is moving and not only when the cursos is release ?
Julien Maxime
Julien Maxime 2022년 9월 27일
편집: Torsten 2022년 9월 27일
Thank you very much for your help really. I dare ask one last question. Here is the relevant code part of the plot:
data = M;
fig = uifigure();
uip = uipanel(fig,'Position', [20 100 500 300]);
hh = heatmap(uip, data(:,:,1),'Colormap', hsv,'CellLabelColor', 'none','ColorLimits', [-360 50]);
title(hh, 'Electrode Fluorescence Heatmap - Frame #1');
n = size(data,3);
uis = uislider(fig,'Position',[50 50 450 3],...
'Value',1, ...
'Limits', [1,n], ...
'MajorTicks', 0:200:n, ...
'MinorTicks', []);
%valueChangedFcn for actualisation only when cursor is dropped
uis.ValueChangingFcn = {@sliderChangingFcn, uip, data};
function sliderChangingFcn(h,~,uip,data)
value = round(h.value);
hh = heatmap(uip,data(:,:,Value), 'Colormap', hsv, 'CellLabelColor', 'none', 'ColorLimits', [-360 50]);
title(hh, sprintf('Electrode Fluorescence Heatmap - Frame #%s',num2str(value)))
end
However, when i slide the cursor it changes the plot one time during the sliding but then stays and lag/block on this last plot. I have to drop it and move it again to diplay a new plot again. I found this guy who had a similar problem but I don't know how to adapt it to my situation: https://www.mathworks.com/matlabcentral/answers/521185-how-to-continuously-change-the-plotted-data-according-to-the-value-obtained-from-a-uislider-compon
Can you help me ?
Thank you very much.
Adam Danz
Adam Danz 2022년 9월 27일
I've updated my answer to use a ValueChangingFcn. The updated answer also updates the existing heatmap rather than recreating it which is much more efficient.
Julien Maxime
Julien Maxime 2022년 9월 28일
Thank you it is perfect!
Adam Danz
Adam Danz 2022년 9월 28일
You may want to set clim so the colorbar limits do not jump around as you update heatmap. You can see this happening in the GIF I shared.
Patricia Darling
Patricia Darling 2025년 7월 29일
편집: Patricia Darling 2025년 7월 29일
Where would I embed clim in the code above. I tried making it stand alone in the main script and in the function and it doesn't seem to be impacting anything.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

질문:

2022년 9월 27일

편집:

2025년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by