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 CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by