Prev: Advanced Stop ODEs
Next: Convert to PDF via MATLAB
From: Adam Parry on 22 Jul 2010 11:01 pretty much what I want to do is to have a slider that when I change the value (by one) it will change the coordinates of a point(my data)(by one) so I can re-plot a gradient.... does that make any sense? can anyone help?
From: Joseph on 22 Jul 2010 14:30 "Adam Parry" <adam.parry-2(a)postgrad.manchester.ac.uk> wrote in message <i29mga$au1$1(a)fred.mathworks.com>... > pretty much what I want to do is to have a slider that when I change the value (by one) it will change the coordinates of a point(my data)(by one) so I can re-plot a gradient.... does that make any sense? > > can anyone help? check out 'uicontrol' You'll want to define the style as 'slider' Let us know how this turns out
From: Adam Parry on 23 Jul 2010 11:58 function slider1_Callback(hObject,eventdata) L = get(hslider1,{'min','max','value'}); E = get(hObject,'value'); disp('L');disp(L{3}); disp('E');disp(E); if E>L{3} set(hslider1,'value',E); b = b+1; elseif E<L{3} set(hslider1,'value',E); b = b-1; else set(hslider1,'value',E); end delete(GRAD); A = [x(b),x(d)]; B = [y(b),y(d)]; p = polyfit(A,B,1); f = polyval(p,x); hold on; GRAD = plot(x,f,'g'); end the problem I'm having is that L=E and so my if statements do nothing!
From: Walter Roberson on 23 Jul 2010 12:11 Adam Parry wrote: > function slider1_Callback(hObject,eventdata) > L = get(hslider1,{'min','max','value'}); > E = get(hObject,'value'); > disp('L');disp(L{3}); > disp('E');disp(E); > if E>L{3} > set(hslider1,'value',E); > b = b+1; > elseif E<L{3} > set(hslider1,'value',E); > b = b-1; > else > set(hslider1,'value',E); > end > delete(GRAD); > A = [x(b),x(d)]; > B = [y(b),y(d)]; > p = polyfit(A,B,1); > f = polyval(p,x); > hold on; > GRAD = plot(x,f,'g'); end > > > the problem I'm having is that L=E and so my if statements do nothing! Recall that this is the callback for the slider, so of course hObject and hslider1 are going to be the same thing. The callback is not called with a _proposed_ new value for the slider object: it is called with the updated value already set in the slider object. If you want to know what the previous value was, you will have to store that somewhere. By the way, recall that sliders can be dragged, and when that happens the user is going to expect b to be changed by more than 1.
From: Adam Parry on 23 Jul 2010 12:18
Ok. I assume I can sort that bit out by taking L-E and adding that on to b or something. But the trouble I am having is this storing of the original value that you are talking about. i am reasonably new to matlab and have pretty much bundled myself through so far. This GUI function business is really above my head. Any advice would be much apreciated. |