Multiples of 5
12 次查看(过去 30 天)
显示 更早的评论
Hi, ive got an array of numbers and i want to delete the array values whose index is a multiple of 5. How can i do this?
0 个评论
采纳的回答
Walter Roberson
2012-5-26
for K = numel(YourArray): -1 : 1
if (K / 5) == fix(K / 5)
YourArray(K) = [];
end
end
There are definitely easier ways, but your question sounds like an assignment.
更多回答(1 个)
Andrei Bobrov
2012-5-26
x - your array
out = x(rem(x,5) ~= 0)
2 个评论
Walter Roberson
2012-5-26
It is the _index_ whose value is a multiple of 5 that is to be affected, not according to the value of the array.
It seems likely to me that this task is homework, so I have refrained from giving the very short and simple solution.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!