MATLAB: How to check this condition? (matlab programming)

programming

Hi,
I have an randomly generated 100 variables between 1 to 20
a=randi(20,1,100)
and another variable b by
b=randi(20,1,100)
Now I want to select 20 values from a and b such that a*b < 64..
how to select 20 such values from a and b so that the above condition is maintained?

Best Answer

At least as I understand the problem, this works:
a=randi(20,1,100); % Initialise random integer arrays
b=randi(20,1,100);
k1 = 1; % Initialise counter and ‘v’
v = [];
while (k1 <= 20) % Limit: 20 pairs of numbers
c1 = a(randi(100)); % Random number from ‘a’
c2 = b(randi(100)); % Random number frin ‘b’
cv = [c1 c2]; % Vector of [a b]
if prod(cv) < 64 % Check: a*b < 64
v = [v; cv]; % If so, add [a b] to ‘v’
k1 = k1 + 1; % Increment counter and continue
end
end