Loop problem...please help
조회 수: 2 (최근 30일)
이전 댓글 표시
Write a MATLAB function that takes a one-dimensional array of numbers (either a
row or column vector), and removes all of the neighboring duplicated numbers. For
example, the array [1 2 2 2 3 0 1 0 0 4] becomes [1 2 3 0 1 0 4]. The function should
return the answer as a one-dimensional array of numbers in the same format as the
input. Your program should use a loop command.
채택된 답변
Walter Roberson
2019년 12월 8일
Take a copy of the input. Go through it starting from the end. If the current entry is the same as the entry before it in the array, delete the current entry.
댓글 수: 2
Walter Roberson
2019년 12월 8일
Starting from the end I said, not from the beginning . And I said to check the previous entry, not the next entr.
And watch out for your boundary condition. If you are at i = 1 then you should not be examining x(i-1)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!