for loop values of certain output range
Show older comments
x=3;
for c= -2:1:2;
for q= -2:1:2;
g= (c*x)+q*(c+x);
h= g(all((g>= 5) & (g<=10)));
disp([ 'at c=', num2str(c), 'at q=', num2str(q), ',g=', num2str(h)])
end
end
this code giving me all the itertions of c, q and the values of h are empty for out of range values and showing the values within the range
but i just want the values of h within the range and their respective c&q only
I really need help on this one, time is a factor.
Accepted Answer
More Answers (1)
Andrei Bobrov
on 5 Sep 2019
x = 3;
c = -2:1:2;
q = -2:1:2;
g = c*x + q.*(c+x);
lo = g >= 5 & g <= 10;
out = table(c(lo),q(lo),g(lo),'Variablenames',{'c','q','g'});
Categories
Find more on Loops and Conditional Statements 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!