Retrieving odd numbers from a matrix
조회 수: 84 (최근 30일)
이전 댓글 표시
Within a matrix, I want to be able to retrieve only odd numbers within the matrix, and place that into its own matrix.
What I have right now is:
x = randn(1,100); odd = mod(x, (x/2))
I'm not able to get the new matrix, odd, to print with the odd values from x, even though I divided by 2, in order to return any values with a remainder. I get an error pointing to the second argument of the function mod.
Where am I going wrong with my code?
Thanks for the help!
댓글 수: 0
답변 (2개)
Andrea Nguyen
2015년 2월 15일
Instead of doing mod(x, x/2) use mod (x, 2)
This will output the odd numbers rather than just dividing it into two. Hope that helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!