how to make a vector z that consists of odd-indexed entries of y (y=[100:1])?

1 次查看(过去 30 天)
y=[100:1];
>> z=

回答(2 个)

KSSV
KSSV 2022-1-20
编辑:KSSV 2022-1-20

John D'Errico
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)
y = 1×8
2 3 5 7 11 13 17 19
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)
z = 1×4
2 5 11 17
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)
u = 1×7
2 3 4 5 6 7 8
As you can see, all primes in that list except for the first are odd numbers.

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by