how to make a vector z that consists of odd-indexed entries of y (y=[100:1])?
조회 수: 1 (최근 30일)
이전 댓글 표시
y=[100:1];
>> z=
댓글 수: 0
답변 (2개)
John D'Errico
2022년 1월 20일
편집: John D'Errico
2022년 1월 20일
A very confusing question. I'll take a wild guess. If this does not answer your question, then you need to be FAR more lear.
y = primes(20)
Now take the elements of y with odd indexes. That is, start at index 1, then 3, then 5, then 7, etc.
z = y(1:2:end)
But maybe you want to know the indexes of the elements in the arry that are odd numbers. How can I possibly know from your question?
u = find(mod(y,2) == 1)
As you can see, all primes in that list except for the first are odd numbers.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!