Multiples of 5

조회 수: 21 (최근 30일)
Edward
Edward 2012년 5월 26일
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?

채택된 답변

Walter Roberson
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
Image Analyst
Image Analyst 2012년 5월 26일
Other ways would be the use the rem() or mod() function.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 5월 26일
x - your array
out = x(rem(x,5) ~= 0)
  댓글 수: 2
Walter Roberson
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.
Edward
Edward 2012년 5월 30일
It wasn't but thanks anyway!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by