필터 지우기
필터 지우기

Issue defending a variable in MATLAB APP Desinger

조회 수: 1 (최근 30일)
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah 2022년 12월 11일
댓글: Walter Roberson 2022년 12월 11일
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.

채택된 답변

Torsten
Torsten 2022년 12월 11일
편집: Torsten 2022년 12월 11일
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
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah 2022년 12월 11일
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
Walter Roberson
Walter Roberson 2022년 12월 11일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by