Slider which changes images
16 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Rik
2019 年 7 月 9 日
編集済み: Rik
2019 年 7 月 9 日
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 件のコメント
Rik
2019 年 7 月 11 日
What is the change? I've show you the way the edit them, what did you try yourself?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Specifying Target for Graphics Output についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!