how to adjust plot with GUI slider without GUIDE

I have a plot that is a sound wave and can be played. I am trying to make a slider that will change the values of w, y, b, and z which will change the linspace and then change the sound in real time. So far I have only made a slider that will adjust the W value. For some reason it will not work. I have no error message, but nothing is changing. What could be the possible issue? thanks
here is a sample of my code
figure
c1=uicontrol('style','pushbutton',...;
'position',[100 50 75 600],... ;%[ left right, up down, width, height]
'backgroundcolor','w',...;
'callback',@sound_g,...;
'string','G'),...
function sound_g(~,~)
Fs=6000;
Ts=1/Fs;
w=1000;
y=2000;
b=3000;
z=4000;
a = linspace(.5, 1, w);
d = linspace(1, .5, y );
s = linspace(0.5, 0.1, b );
r = linspace(.1, 0, z);
adsr = [a d s r];
t=[0:length(adsr)-1] ;
fc=392;
y=sin(2*pi*fc*t/Fs);
o=y.*(adsr);
sound(o,Fs)
plot(o)
SliderH = uicontrol('style','slider','position',[175 400 200 20],...
'min', -10000, 'max', 10000);
addlistener(SliderH, 'Value', 'PostSet', @slidercall);
function slidercall(source, eventdata)
end
end

回答(1 个)

You don't use the actual value of the slider, so nothing will change.
function sound_g(hObject,~)
val=get(hObject,'Value');
And why do you create a slider inside the callback?

3 个评论

For my own use I don't put the slider in the callback, it is in my figure instead. It is just like this to be compact in my question.
I still see no indication of where you get the Value from the slider object.
Creating the slider inside the callback is needed for to be able to set its Callback property to a handle to the nested function slidercall . slidercall is deliberately nested because it shares variables with sound_g
Note though that you are creating a new slider in the same position every time you push the button.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by