Basic question regarding adding A to all numbers greater than B
5 次查看(过去 30 天)
显示 更早的评论
For example, if I have an array like x = (1:10); How would I add 2 to each number in that array that is greater than 5?
0 个评论
回答(1 个)
James Blackwell
2018-2-1
You could have an if function and go through the array element by element. If the number is greater than 5 you could add 2 to it :)
It sounds a bit like a homework question, so I don't think I'm supposed to give the code.
3 个评论
Steven Lord
2018-2-1
Since your homework assignment prohibits using if, its purpose is likely to familiarize you with logical indexing.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!