Why my variable is not defined in this scope?

11 ビュー (過去 30 日間)
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah 2022 年 12 月 11 日
回答済み: Dongyue 2022 年 12 月 15 日
I have the following function
dq_k = [];
for i1 = 1:numel(d_k)
if (d_k(i1) <= dR(end) && d_k(i1) >= dR(end-1)) % greater than or equal to maximum interval
dqe1 = dR2(end); % use maximum interval value
else
for i2 = 1:L-1
if (d_k(i1) <= dR(end-i2)) && (d_k(i1) >= dR(end-i2-1))
dqe1 = dR2(end-i2);
end
end
end
dq_k = [dq_k dqe1];
end
everytime I run it inside my whole code
it gives me this error
Unrecognized function or variable 'dqe1'.
Error in Trial2222 (line 63)
dq_k = [dq_k dqe1];
And here are my input varaibles to this function
dR =
1.0000 2.5000 4.0000 5.5000 7.0000
dR2 =
1.7500 3.2500 4.7500 6.2500
d_k =
1.0000 1.0000 0.2500 -0.5000 -1.2500 -2.0000 -2.7500
  2 件のコメント
Stephen23
Stephen23 2022 年 12 月 11 日
Check the value of L .
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah 2022 年 12 月 11 日
I put its value to be 4, and I calculated the dR and dR2 based on L value as following
m_kmax= max(m_k);
m_kmin= min(m_k);
stepsize=((m_kmax-m_kmin)/L);
if tread == 1
dR =linspace(m_kmin,m_kmax,L+1);
else
dR= stepsize + linspace(m_kmin,m_kmax,L+1);
end
dR2=zeros(1,L);
for i=1:L
dR2(i) = ( dR(i) + dR(i+1)) ./ 2;
end
But what I just figured is my function attached in this comment, which was supposeded to switch Quantizier between midrise or midtread is not actually doing what it was supposed to do, that's why I am considering adjusting it.

サインインしてコメントする。

回答 (1 件)

Dongyue
Dongyue 2022 年 12 月 15 日
If the two conditions:
if (d_k(i1) <= dR(end) && d_k(i1) >= dR(end-1))
and
if (d_k(i1) <= dR(end-i2)) && (d_k(i1) >= dR(end-i2-1))
are both not met, dqe1 will not be created unless you set default value for it.

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by