Function in App-Designer struggles to read dropdown values
7 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Simon Chan
on 20 Aug 2022
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 Comments
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!