Function in App-Designer struggles to read dropdown values

9 次查看(过去 30 天)
Hi,
i want to build a very simple app with code that works fine in the regular matlab-editor. In App-Designer i tried to implement just a start-button to run the code and 2 dropdown-lists to select input for the main function.
When i run the programm it seems like the main-function works, but has struggle to read the values from the dropdown lists. See the example below:
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton (This is the code i wrote in
% the regular editor.)
function StartButtonPushed(app, event)
% Sample rate
fs = 48000
adr = audioDeviceReader(fs);
buff = dsp.AsyncBuffer(Capacity = fs*3);
numIterations = floor(450*fs/adr.SamplesPerFrame);
o=1;
for index=1:numIterations
frame = adr();
write(buff,frame);
if buff.NumUnreadSamples >= 2*fs
o=o+1;
data = read(buff);
[psp, f] = pspectrum(data,fs);
f_index = find(f >= app.minFrequencyDropDown.Value & f <= app.maxFrequencyDropDown.Value);
p = 10*log10(psp(f_index));
m(o,:) = mean(p) %m is the value im interested in!
end
end
end
% Value changed function: minFrequenzDropDown
function minFrequencyDropDownValueChanged(app, event)
value = app.minFrequencyDropDown.Value;
end
% Value changed function: maxFrequenzDropDown
function maxFrequencyDropDownValueChanged(app, event)
value = app.maxFrequencyDropDown.Value;
end
i tried setting properties like "minFrequency" and "maxFrequency" and i tried different syntax in the dropdown functions, but somehow i keep getting NaN Values in m(o,:)
Really appreciate any help! Thanks.

采纳的回答

Simon Chan
Simon Chan 2022-8-20
Use function str2double as follows:
% Value changed function: minFrequenzDropDown
function minFrequencyDropDownValueChanged(app, event)
value = str2double(app.minFrequencyDropDown.Value);
end
% Value changed function: maxFrequenzDropDown
function maxFrequencyDropDownValueChanged(app, event)
value = str2double(app.maxFrequencyDropDown.Value);
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by