How to use a slider
Show older comments
Hello, I am preparing a class on phasors. I want to make a symple plot for an RC circuit, in which I want to include a slider to vary frecuency and change the phasors. Does anyone have any pointers? I um struggling with the uicontrols. This is one plot, but I have not been able to make the slider work (I excluded here the things I tried, because I'm pretty lost). The slider should update w, I have tried making the plot as a function of a), but do not know how to update the parameter from the slider value.
Thank you
close all
clear
clc
%----
R=1000;%ohm
C=100*10^(-9);%nf
V0=1;
%---------
fc=1/(R*C*2*pi);
%w=@(a)a;
w=2*pi*fc;
%----
fig=figure;
I0=V0./(R-(1i/(w*C)));
VR=I0*R;
VC=-(1i./(C.*w))*I0;
c=compass([V0,VR,VC]);
c1=c(1);
c1.LineWidth=2;
c2=c(2);
c2.LineWidth=2;
c2.Color='r';
c3=c(3);
c3.LineWidth=2;
c3.Color='g';
legend('V0','VR','VC');
set(gca,'FontSize',18)
%-----Slider---------
b = uicontrol('Parent',fig,'Style','slider','Position',[81,54,419,23],...
'value',w, 'min',0.01*2*pi*fc, 'max',15*2*pi*fc);
bgcolor = c.Color;
bl1 = uicontrol('Parent',fig,'Style','text','Position',[50,54,50,50],...
'String','0.01fc','BackgroundColor',bgcolor);
bl2 = uicontrol('Parent',fig,'Style','text','Position',[500,54,50,50],...
'String','15fc','BackgroundColor',bgcolor);
bl3 = uicontrol('Parent',fig,'Style','text','Position',[240,25,100,23],...
'String','Frecuencia','BackgroundColor',bgcolor);
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB 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!