Issue defending a variable in MATLAB APP Desinger

I have a button taking a value from the user
% Value changed function: Freq_input2
function Freq_input2ValueChanged(app, event)
fm = app.Freq_input2.Value
app.Freqout.Value=fm;
end
and I defined fm in the main Properties as
properties (Access = private)
fm
amp
L
tread
p
end
Then I wanted to design a calculate (Push button) to perform certain analayiss,and I wanted to use this fm to calculate time vector
function Calculate_toggleButtonPushed(app, event)
fs=20*(app.fm)
N=10; % ?? For usage later on
t=-1:1/fs:1
m_k=app.amp*cos(2*pi*app.fm*t);
...
...
end
i get this error message
Error using /
Matrix dimensions must agree.
Error in NewGui/Calculate_toggleButtonPushed (line 118)
t=-1:1/fs:1
Error while evaluating Button PrivateButtonPushedFcn.

 Respuesta aceptada

Torsten
Torsten el 11 de Dic. de 2022
Editada: Torsten el 11 de Dic. de 2022
If fs is a vector of values, you have to use elementwise division:
1./fs
instead of
1/fs
Same for
m_k = app.amp.*cos(2*pi*app.fm.*t);
instead of
m_k=app.amp*cos(2*pi*app.fm*t);

4 comentarios

that's what I did
fs=0;
fs=20.*(app.fm)
N=10; % ?? For usage later on
t=-1:1./fs:1
%
% m_k=app.amp.*cos(2*pi*app.fm.*t);
But it gives me fs as an empty vector, while i need it as one value scaler
Command Window output
fm =
1
fs =
[]
t =
1×0 empty double row vector
Torsten
Torsten el 11 de Dic. de 2022
fm is 1, but app.fm is empty.
then how can I call the value of fm?
I thought I would just use app.fm no? because it's decalred inside another function
You are assigning to local variable fm in the function, not to app.fm. The function does save the value but into a different location, not app.fm

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 11 de Dic. de 2022

Comentada:

el 11 de Dic. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by