I am dealing with a 3D double which I want to visualize slice by slice.
To do that, I tried plotting a heatmap and then adding a slider to select the index for the third dimension.
However, I get the following error:
Error using uislider (line 34) HeatmapChart cannot be a parent.
A minimal example to reproduce my problem:
% Generate dummy 3d array
img = ones(5,4,3);
for ii=1:size(img,3)
img(:,:,ii)=ii;
end
% Try plotting heatmap with slider
h = heatmap(img(:,:,1));
uislider(h)
Is there actually a way/workaround to use a slider on a heatmap?
Thanks!

 채택된 답변

Ines Pereira
Ines Pereira 2021년 2월 2일
편집: Ines Pereira 2021년 2월 2일

0 개 추천

This question was answered here.

추가 답변 (1개)

Mario Malic
Mario Malic 2021년 2월 2일
편집: Mario Malic 2021년 2월 2일

2 개 추천

Hello,
I modified your code a little bit. Uislider can only be used on uifigure components. Whenever you're using uifigure you need to specify axes handle, because uifigure's handle visibility by default is set to 'off'.
UIFigure = uifigure;
img = ones(5,4,3);
img(:,:,2) = img(:,:,2)*2;
img(:,:,3) = img(:,:,3)*3;
% Try plotting heatmap with slider
h = heatmap(UIFigure, img(:,:,1));
UISlider = uislider(UIFigure);
UISlider.Limits = [1, 3];
UISlider.MajorTicks = 1:3;
UISlider.MinorTicks = 1:3;
UISlider.ValueChangedFcn = {@UISliderValueChangedFcn, img};
function UISliderValueChangedFcn(Source, ~, img)
sliderValue = round(Source.Value); % We need to round the decimal value we get from UISlider.Value to index into img
Source.Value = sliderValue; % Change slider to rounded value to show it on UIFigure
UIFigure = Source.Parent;
h = heatmap(UIFigure, img(:,:,sliderValue));
end
However, this uislider is not nicely position on UIFigure, so you can use Position property for both components to set their size and location.

댓글 수: 3

Ines Pereira
Ines Pereira 2021년 2월 2일
Hey Mario, thanks for checking in on this! Ok so your code does display the slider, but it doesn't allow me to view slices of my tensor. I got a workaround from StackOverflow which I'll post here.
Mario Malic
Mario Malic 2021년 2월 2일
I edited the example so it can be used with UISlider component.
Ines Pereira
Ines Pereira 2021년 2월 2일
Really cool! Works now, thank you!

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

카테고리

제품

릴리스

R2020a

태그

질문:

2021년 2월 2일

댓글:

2021년 2월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by