Azzera filtri
Azzera filtri

Creating an interactive contour plot using a slider

27 visualizzazioni (ultimi 30 giorni)
Ellie
Ellie il 24 Giu 2024 alle 19:41
Commentato: Matlab Pro il 26 Giu 2024 alle 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 Commento
Matlab Pro
Matlab Pro il 24 Giu 2024 alle 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?

Accedi per commentare.

Risposta accettata

Matlab Pro
Matlab Pro il 24 Giu 2024 alle 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 Commenti
Ellie
Ellie il 25 Giu 2024 alle 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 il 26 Giu 2024 alle 7:13
Hi @Ellie.
If you find the answer OK - please "accept" the answer

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by