"Slider control can not have a Value outside of Min/Max Range"

3 次查看(过去 30 天)
I am getting this error for a code that I know is correct and should work. Why am I getting this? Here is the code:
function TriadF(handles)
% Triad.m
% Play a musical major triad chord
%%Set Parameters
duration = 2; % length of audio duration, s
add1 = true; % adds tonic
add3 = false; % adds major third
add5 = false; % adds perfect fifth
add8 = false; % adds octave
playSound = true; % play sound
f1 = 440; % tonic frequency, Hz
f3 = f1*(5/4); % major third frequency, Hz
f5 = f1*(3/2); % perfect fifth frequency, Hz
f8 = f1*(2); % octave frequency, Hz
%%Calculate function values
fsample = 8000; % sample frequency, Hz (8000 for proper audio)
Nsamples = fsample*duration;
t = linspace(0,duration,Nsamples); % time points
y1 = sin(2*pi*f1*t); % set up sine waves for each frequency
y3 = sin(2*pi*f3*t);
y5 = sin(2*pi*f5*t);
y8 = sin(2*pi*f8*t);
%%Combine to create final signal
y = zeros(1,Nsamples);
% Use a series of if statements to
if add1
y = y + y1;
end
if add3
y = y + y3;
end
if add5
y = y + y5;
end
if add8
y = y + y8;
end
% final wave form should be limited to +/- 1 for proper audio
y = y/max(y);
%%Plot function points
% plot first 200 points of waveform
plot(t(1:200),y(1:200))
xlabel('t')
ylabel('y')
%%play sound
if playSound
sound(y)
end

回答(2 个)

Image Analyst
Image Analyst 2013-4-17
There is no mention of handles, much less a slider, in your function. The code you posted will not cause the error you mention. It must be caused by some other code.
  1 个评论
Image Analyst
Image Analyst 2013-4-17
There's no mention of setting a slider value in that code, your "Answer". If you get an error, it's because it's already set up that way (improperly) in GUIDE with the value property being outside of your min and max range. Tell me, in GUIDE, what are the values of min, max, and value for all the sliders on your GUI.

请先登录,再进行评论。


Kelsey
Kelsey 2013-4-17
编辑:Kelsey 2013-4-17
Well here's the same basic function, altered for my GUI:
function TriadF(handles)
% TriadF.m
% Play a musical major triad chord
%%Set Parameters
duration = get(handles.timeSlider,'Value'); % length of audio duration, s
add1 = get(handles.tonicCheckbox,'Value'); % adds tonic
add3 = get(handles.majorthirdCheckbox,'Value'); % adds major third
add5 = get(handles.perfectfifthCheckbox,'Value'); % adds perfect fifth
add8 = get(handles.octaveCheckbox,'Value'); % adds octave
playSound = get(handles.playButton,'Value'); % play sound
f1 = get(handles.tonicfrequencySlider,'Value'); % tonic frequency, Hz
f3 = f1*(5/4); % major third frequency, Hz
f5 = f1*(3/2); % perfect fifth frequency, Hz
f8 = f1*(2); % octave frequency, Hz
%%Calculate function values
fsample = 8000; % sample frequency, Hz (8000 for proper audio)
Nsamples = fsample*duration;
t = linspace(0,duration,Nsamples); % time points
y1 = sin(2*pi*f1*t); % set up sine waves for each frequency
y3 = sin(2*pi*f3*t);
y5 = sin(2*pi*f5*t);
y8 = sin(2*pi*f8*t);
%%Combine to create final signal
y = zeros(1,Nsamples);
% Use a series of if statements to
if add1
y = y + y1;
end
if add3
y = y + y3;
end
if add5
y = y + y5;
end
if add8
y = y + y8;
end
% final wave form should be limited to +/- 1 for proper audio
y = y/max(y);
%%Plot function points
% plot first 200 points of waveform
plot(handles.graphAxes,t(1:200),y(1:200))
xlabel('t')
ylabel('y')
%%play sound
if playSound
sound(y)
end
I get the same error message whether I run either code...

类别

Help CenterFile Exchange 中查找有关 Measurements and Spatial Audio 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by