Function in App-Designer struggles to read dropdown values

1 回表示 (過去 30 日間)
Oskar Kilgus
Oskar Kilgus 2022 年 8 月 20 日
回答済み: Simon Chan 2022 年 8 月 20 日
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 Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by