Slider which changes images
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear Friends,
COuld you suggest me how to do this.
I have a program in matlab where in , the XY graph is a function of applied voltage.
When i change the votlage, the shape of the graph also changes in the way as shown in the three pics.
I want to create a slider (where the slider drag represents the voltage) and want the XY graph to change as the slider is moved.
But i dont know how to do it. Can anyone suggest me a way to deal with this.
Thanking you.
0 commentaires
Réponse acceptée
Rik
le 9 Juil 2019
Modifié(e) : Rik
le 9 Juil 2019
Live updates are a bit more tricky, but you can use the uicontrol function to create a slider. Then you can use the callback function to change the YData according to your selected voltage. (changing the YData property of you line object is much faster than clearing the axes and calling plot again).
Let me know if you need a small example.
Edit:
The example below shows how you could create a GUI that helps you find out the effect of changing a particular value in polyval. This examples works with continuous data, but your situation might not. You can use round on the Value property to ensure interger outputs.
h=struct;%prepare guidata struct
h.f=figure(999);clf(h.f)%open a clean figure
h.ax=axes('Parent',h.f,...
'Units','Normalized',...
'Position',[0.1 0.2 0.8 0.75]);
%prepare data
h.x=linspace(0,1,1000);
h.p=[6.5 -15 NaN -3 0];
%initialize plot
p=h.p;p(3)=0;
y=polyval(p,h.x);
h.line=plot(h.x,y,'Parent',h.ax);
%create slider
h.slider=uicontrol('Parent',h.f,...
'Units','Normalized',...
'Position',[0.1 0.05 0.8 0.09],...
'Style','slider',...
'Min',5,'Max',15,'Value',10,...
'Callback',@slider_callback);
h.legend=legend(h.line,sprintf('V=%.1f',p(3)));
%store handles and data to guidata
guidata(h.f,h)
function slider_callback(hObject,eventdata) %#ok<INUSD>
h=guidata(hObject);%retrieve struct
p=h.p;p(3)=get(hObject,'Value');%set slider value to p(3)
y=polyval(p,h.x);
set(h.line,'YData',y)%update plot
set(h.legend,'String',{sprintf('V=%.1f',p(3))})%update legend
end
14 commentaires
Rik
le 11 Juil 2019
What is the change? I've show you the way the edit them, what did you try yourself?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!