필터 지우기
필터 지우기

Creating an interactive contour plot using a slider

조회 수: 27 (최근 30일)
Ellie
Ellie 2024년 6월 24일 19:41
댓글: Matlab Pro 2024년 6월 26일 7:13
This is a fairly general question. I am working on a project and have been provided GPR data. I have successfully generated contour plots, but was wondering if there was a way to utilize a slider to create an interactive contour map. Ideally, the end result would be the ability to slide and select the layer (out of 512) and view that respective contour plot. So far, looking into it, I have not been able to find any guidance on how to utilize the slider with contour plots specifically.
  댓글 수: 1
Matlab Pro
Matlab Pro 2024년 6월 24일 20:50
I am less familiar with GPR data
Do you mean "Ground Penetrarting Radar" data?
anyhow - is what you mean is that the GPR data consists of 512 layres of heatmaps (each, lets say is 1000x1000 pixels) and using the slide: slider value = which layer contour to view?

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

채택된 답변

Matlab Pro
Matlab Pro 2024년 6월 24일 22:10
well, I have created some dummy example with 40 levels depth
The uifigure 1st is loaded with the whole contour.
Changing the slider values - displays 4 differnt contour types - based on the DropDown
I am sure that one of the 4 options - is what you were looking for,,,
function contour_test()
NLevels = 40;
x = -2:0.01:2;
y = -2:0.01:3;
[X,Y] = meshgrid(x,y);
Z = X.*exp(-X.^2-Y.^2);
z0 = min(Z(:));
z1 = max(Z(:));
levels = linspace(z0,z1,NLevels);
fig = uifigure;
g = uigridlayout(fig);
g.RowHeight = {30, '1x'};
g.ColumnWidth = {'1x',60};
% Range drop-down
dd2 = uidropdown(g);
dd2.Items = {'all','1st level till..','from both sides','single countour'};
dd2.Layout.Row = 1;
dd2.Layout.Column = 1;
dd2.ValueChangedFcn = @sliderCallback;
ax = uiaxes(g);
ax.Layout.Row = 2;
ax.Layout.Column = 1;
ax.UserData = levels;
contour(X,Y,Z,levels,'Parent',ax)
sl = uislider(g);
sl.Orientation = 'vertical';
sl.Layout.Row = [1, 2];
sl.Layout.Column = 2;
sl.Limits = [1, NLevels];
sl.ValueChangedFcn = @sliderCallback;
end
%=============================================
function sliderCallback(hObject,eventData)
fig = ancestor(hObject,'figure','toplevel');
ax = findall(fig,'type','axes');
sl = findall(fig,'type','uislider');
val = sl.Value;
X = ax.Children.XData;
Y = ax.Children.YData;
Z = ax.Children.ZData;
levels = ax.UserData;
dd = findall(fig,'Type','uidropdown');
items = dd.Items;
switch dd.Value
case items{1}
contour(X,Y,Z,levels,'Parent',ax)
case items{2}
contour(X,Y,Z,levels(1:floor(val)),'parent',ax);
case items{3}
contour(X,Y,Z,val,'parent',ax);
case items{4}
v = levels(floor(val));
contour(X,Y,Z,[v v],'parent',ax);
end
end
Have fun!
  댓글 수: 2
Ellie
Ellie 2024년 6월 25일 15:41
I will be sure to try this out!! I thank you for the earnest and in depth answer, this is a long term project and I am fairly new to matlab. I appeciate it.
Matlab Pro
Matlab Pro 2024년 6월 26일 7:13
Hi @Ellie.
If you find the answer OK - please "accept" the answer

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by