Why my variable is not defined in this scope?
    7 views (last 30 days)
  
       Show older comments
    
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 Comments
Answers (1)
  Dongyue
    
 on 15 Dec 2022
        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. 
0 Comments
See Also
Categories
				Find more on Downloads in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

