how can i slove this proplem "- The vector V is given by V=[2 8 7 3 1 0 8 9]. Write down a single instruction to produce a vector that contains 1 in the place of the odd numbers and -1 in the place of the even numbers."
1 次查看(过去 30 天)
显示 更早的评论
- The vector V is given by V=[2 8 7 3 1 0 8 9]. Write down a single Matlab instruction to produce a vector that contains 1 in the place of the odd numbers and -1 in the place of the even numbers.
采纳的回答
Fabio Freschi
2019-10-13
A suggestion: you can easily find the reminder of the division by 2, so that even numers have reminder 0 and odd numbers reminder 1. Now you should map these numbers to -1 and 1, respectively. The problem is that you must write a single instruction, so you can play with algebra: multiply by 2 and subtract 1. From now on it's just a translation of this idea in matlab language
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!