find the reptition in vector
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
HI,I have x=[2 4 4 1 1],I want if the number is not repeated like 2 to execute a condition.If repeated ,to execute another condition.
1 Commento
Image Analyst
il 6 Apr 2014
Modificato: Image Analyst
il 6 Apr 2014
So, for this x, are you going to execute the operation 1 or 2, or not? You have both unique and repeated numbers in this array, so which "condition" or operation are you going to execute????
Risposta accettata
yousef Yousef
il 6 Apr 2014
3 Commenti
Image Analyst
il 6 Apr 2014
Modificato: Image Analyst
il 6 Apr 2014
No, it means he's going to abandon this conversation and start a duplicate one, which he's already done. Grrrrr.
Jan
il 6 Apr 2014
While I still do not understand the original question, I have the faint impression, that "Grrrr" is a special kind of "the problem is solved".
Più risposte (1)
Image Analyst
il 6 Apr 2014
Is this what you want:
x=[2 4 4 1 1]
ux = unique(x)
counts = histc(x, ux) % Histogram
for k = 1 : length(ux)
checkValue = ux(k);
if counts(k) == 1
fprintf('Execute operation 1 because %d is unique.\n', checkValue);
else
fprintf('Execute operation 2 because %d is repeated.\n', checkValue);
end
end
In the command window:
x =
2 4 4 1 1
ux =
1 2 4
counts =
2 1 2
Execute operation 2 because 1 is repeated.
Execute operation 1 because 2 is unique.
Execute operation 2 because 4 is repeated.
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!