Clear Filters
Clear Filters

Creating an interactive contour plot using a slider

27 views (last 30 days)
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 Comment
Matlab Pro
Matlab Pro on 24 Jun 2024 at 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?

Sign in to comment.

Accepted Answer

Matlab Pro
Matlab Pro on 24 Jun 2024 at 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 Comments
Ellie
Ellie on 25 Jun 2024 at 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 on 26 Jun 2024 at 7:13
Hi @Ellie.
If you find the answer OK - please "accept" the answer

Sign in to comment.

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!