Add a slider to quiver vector plot using Callback
    8 views (last 30 days)
  
       Show older comments
    
    Karthik Brs
 on 17 Nov 2015
  
    
    
    
    
    Answered: Satyajeet Sasmal
    
 on 19 Nov 2015
            Hello Everyone! I am required to add a vector 'rpm' as a slider in the quiver plot. I am plotting the vector fields of reaction forces(x and y components). I want the vector fields to change as I change the Slider('rpm'). I am including my code with this query. My code plots the vector fields of 3 vectors at the point (0,0) and displays the slider with the maximum and minimum values of 'rpm' vector. But, I am failing to connect the 'rpm' vector to the slider and consequently to the vector field(quiver command). I read online that the 'Callback' could help me, but I don't know how to integrate it into my code!
Thank you in advance!
rpm = [1000 900 800];
range = 0:0.1:2*pi;
minrpm = min(rpm);
maxrpm = max(rpm);
y = [0 -0.9 0];
Fy =[1 .5 1];
yy = [92 10 150];
alpha_y = degtorad(yy);
x = [0 0.4 0];
Fx = [.8 .7 1.1];
xx = [90 15 80];
alpha_x = degtorad(xx);
hFig = figure;                                      % to define Figure Properties
set(hFig, 'Position', [0 0 1000 1000]);
for e = 1:length(range);
    q = quiver(x, y, Fx.*cos(alpha_x+range(e)), Fy.*cos(alpha_y+range(e)),1,'LineWidth',2);
    F_total(e)= sqrt((Fx(1).*cos(alpha_x(1)+range(e)))^2+(Fy(1).*cos(alpha_y(1)+range(e)))^2);
    axis([-1.1 1.1 -1.1 1.1]);
    M(e) = getframe;
    sld = uicontrol(hFig,'Style','slider','Min',min(rpm),'Max',max(rpm),'Value',900,'Position', [81,54,419,23]);
    bl1 = uicontrol('Parent',hFig,'Style','text','Position',[50,54,23,23],'String',minrpm);
    bl2 = uicontrol('Parent',hFig,'Style','text','Position',[500,54,23,23],'String',maxrpm);
    bl3 = uicontrol('Parent',hFig,'Style','text','Position',[240,25,100,23],'String','RPM');% Center and Size of Window
end
0 Comments
Accepted Answer
  Satyajeet Sasmal
    
 on 19 Nov 2015
        In your code, change the sld = uicontrol(hfig,....) to
sld =
uicontrol(hFig,'Style','slider','Min',min(rpm),'Max',max(rpm),'Value',900,'Position', [81,54,419,23], 'CallBack',{@sliderFcn});
Now, create a function "sliderFcn" as below:
function sliderFcn(hobj,~)
     val = hobj.Value;
end
where, "val" contains the slider value. You can use this to make required changes to your code. Hope this was helpful.
-Satya
0 Comments
More Answers (0)
See Also
Categories
				Find more on Vector Fields 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!
