Use slider for live updating of threshold on 2D contour plot?

8 views (last 30 days)
I currently have a system for certain types of data where after processing it, I need to plot it out in a contour plot, but only after applying a threshold to it. What I mean by this is that the code I use to generate the contour plot is as follows:
v = (get(findobj('tag','threshold'),'value')):0.01:100;
fullscreen = get(0,'ScreenSize');
figure('Position',[0 -1 fullscreen(3) fullscreen(4)])
contour(qx, qy, qz,v); hold on;
At present, I have my data processing script set up so that at the end, a GUI pops up with a slider bar on it. I use this slider bar to select the value for 'threshold' and then press a button on the GUI that calls my contour plotting script.
However, since the exact threshold level requires some fine tuning, it would be nice if I could instead embed the slider bar as part of the contour plot itself and have it so that every time I adjust the slider bar, the graph automatically updates.
I've tried using linkdata and refreshdata, but they don't seem to work for adjusting the variable that I want. Is it at all possible to do this sort of thing? Thanks for any help you can offer

Accepted Answer

Ben11
Ben11 on 7 Jul 2014
My best guess would be to add a listener object inside your slide bar Create function. For instance you could add this line:
hListenerTreshold = addlistener(hObject,'ContinuousValueChange',@(a,b) UpdateTreshold);
Where UpdateTreshold is the function you would use to actually apply the treshold and display the result, which I believe you have already coded. Then when you move the slider the treshold will update quite smoothly.
  3 Comments
Ben11
Ben11 on 7 Jul 2014
I would put the line after setting up the slider,replacing the "hObject" in my answer" with "hs", which is the handle to your slider. You would then have this:
hs = uicontrol(h,...
'style','slider',...
'pos',[10 40 280 20],...
'min',span(1),...
'max',span(2),...
'value',span(1),...
'callback',@sliderupdate,...
'tag',varname);
hListener = addlistener(hs,'ContinuousValueChange',@(a,b) sliderupdate);
In this case, the callback to "hs" is executed when you release the slider after dragging it around whereas the listener is executed as you move it along, since Matlab keeps track of the slider's position when it is being dragged.
Here is a very simple example which you can copy/paste directly in your workspace:
hs = uicontrol('Style','slider','Callback',@(a,b) disp('I''m not moving'));
hListener = addlistener(hs,'Value','PostSet',@(a,b) disp('I''m moving!'));
I don't really know why but if I run the previous example with the callback type "ContinuousValueChange" Matlab might throw an error saying "callback types have to be one of {PostSet,PostGet,PreGet,PreSet} and match case". I can't say whether it depends on your version, but try one or the other and it should work :) You might also find useful information from this website:

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!