Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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 Kommentar
Randy Souza
Randy Souza am 25 Feb. 2013
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 23 Feb. 2013
if i ~= 6 & myvec(i+1)==myvec(i)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by