フィルターのクリア

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 Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by