how to adjust plot with GUI slider without GUIDE

조회 수: 11 (최근 30일)
bella bridges
bella bridges 2018년 6월 8일
편집: bella bridges 2018년 6월 10일
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
Walter Roberson
Walter Roberson 2018년 6월 8일
What is LineH and why are you setting its YData?

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
Rik 2018년 6월 8일
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
Rik
Rik 2018년 6월 8일
I still see no indication of where you get the Value from the slider object.
Walter Roberson
Walter Roberson 2018년 6월 8일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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