How do I remove duplicate values from vector without using unique (out of bounds problem)?

2 次查看(过去 30 天)
I have a vector of numbers which has 6 elements from user input.
I want to replace any duplicate values with another value.
I tried:
myvec=zeros(1,6);
disp('Choose numbers from 1 to 55')
for i=1:6
myvec(i)=input('');
if (find(myvec(i)<1 | myvec(i)>55))
disp('Enter new value')
myvec(i)=input('');
end
if myvec(i+1)==myvec(i)
myvec(i+1)==input('');
end
end
My questions are:
1) Is the statement below correct?
if myvec(i+1)==myvec(i)
myvec(i+1)==input('');
end
2) When running it gives out of bounds because the vector length is 6 and I am trying to access i+1. I tried to use the for loop from 2:7 but then it adds in the myvec vector the zero as first element.
  1 个评论
Randy Souza
Randy Souza 2013-2-25
I have restored the original text of this question.
George, this question has a clear subject and answer, so it may be valuable to someone else in the future. If you have a good reason why it should be removed from MATLAB Answers, please flag the question, explain why it should be deleted, and an administrator or high-reputation contributor will consider deleting the question. Please do not simply edit your question away.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2013-2-23
if i ~= 6 & myvec(i+1)==myvec(i)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by