필터 지우기
필터 지우기

find the reptition in vector

조회 수: 2 (최근 30일)
yousef Yousef
yousef Yousef 2014년 4월 6일
댓글: Jan 2014년 4월 6일
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
Image Analyst
Image Analyst 2014년 4월 6일
편집: Image Analyst 2014년 4월 6일
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????

댓글을 달려면 로그인하십시오.

채택된 답변

yousef Yousef
yousef Yousef 2014년 4월 6일
Its OK.Thanks. if you are still interested:
2 82 10 16 15 66 76 71 83 44 49
4 91 28 98 43 4 75 4 70 39 45
4 13 55 96 92 85 40 28 32 77 65
1 92 96 49 80 94 66 5 96 80 71
1 64 97 81 96 68 18 10 4 19 76
I want the prog. to check each element of the first column.if it is not repeted,then take the first k large numbers of the row along with their indices and put them in matrix. if not take the first large k numbers and give them to the first repeat then give the rest to the next one. I think the condition must include sort command
  댓글 수: 3
Image Analyst
Image Analyst 2014년 4월 6일
편집: Image Analyst 2014년 4월 6일
No, it means he's going to abandon this conversation and start a duplicate one, which he's already done. Grrrrr.
Jan
Jan 2014년 4월 6일
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".

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 4월 6일
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.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by