Effacer les filtres
Effacer les filtres

App Designer - Reading Value from Edit Field at Startup

3 vues (au cours des 30 derniers jours)
PADMAKAR
PADMAKAR le 4 Mar 2022
I am reading a value from Edit field and performing simple computation. The computation is incorrect. Where is the error coming from? See pictures and code below.
function startupFcn(app)
%--------------------------------------------------------------------------
% Create an Ricker wavelet using Ricker function from CREWES function list
%--------------------------------------------------------------------------
% wl=wavelet length in seconds
app.sr=app.SampleIntmsEditField.Value; % The value of 1 ms is read correctly. See picture 1.
app.sr=app.sr/1000;% The computed value is 0.049 instead of 0.001 What is causing this error?
tw=app.NoOfSamplesEditField.Value;
Fs=1/sr;
wl=sr/Fs*length(tw)- (sr/Fs);%subtract one sample in sec.since the ricker fn adds one sample to time vector
[wr,tw2] = ricker2(sr/Fs,fpeak,wl);%ricker2 function also returns time vector tw2 with tw2=wl+1 sample
tw2=tw2*Fs;
end

Réponse acceptée

Cris LaPierre
Cris LaPierre le 4 Mar 2022
Modifié(e) : Cris LaPierre le 5 Mar 2022
Pay attention to data types. Your value of 1 is a char, not a double. You must be using a text edit field instead of a numeric edit field. Try replacing it with the Edit Field (Numeric) component and then rerun your calculation.
sr = '1'
sr = '1'
sr/100
ans = 0.4900

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by