Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
George
George le 23 Fév 2013
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 commentaire
Randy Souza
Randy Souza le 25 Fév 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.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 23 Fév 2013
if i ~= 6 & myvec(i+1)==myvec(i)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by