Function in App-Designer struggles to read dropdown values
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Simon Chan
il 20 Ago 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!