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개)

Rik
Rik 2018년 6월 8일

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.
Rik
Rik 2018년 6월 8일
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에 대해 자세히 알아보기

질문:

2018년 6월 8일

편집:

2018년 6월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by