Make a vector based on for loop values
5 次查看(过去 30 天)
显示 更早的评论
I need to make a code to find the number of values between 120 and 230 that are odd and are multiples of 11 and 13, then store the answers in a vector. I can't quite figure out how to make a vector based on the for loop. All I can manage to get is
n = [120:+1:230];
for n = 120:230;
if mod(2,2) == 1;
else mod(n,11) == 0 && mod(n,13) == 0;
end
end
2 个评论
Stephen23
2020-10-7
Is it a requirement to use a loop? The MATLAB approach would be to use logical indexing without any loop.
采纳的回答
madhan ravi
2020-10-7
You are close:
if (mod(n,2) == 1)&& (mod(n,11) == 0 || mod(n,13) == 0);
If the above statement is true , you will save n in a variable.
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!