Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Randy Souza
Randy Souza il 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.

Accedi per commentare.

Risposte (1)

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

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by