Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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 comentario
Randy Souza
Randy Souza el 25 de Feb. de 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.

Iniciar sesión para comentar.

Respuestas (1)

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

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by