How to return a true/false logical array from a string array of repeating numbers?
조회 수: 10 (최근 30일)
이전 댓글 표시
ans = 3 2 1 5 1 4 0
I want this to return a 7x1 logical array 0 0 1 0 1 0 0. Corresponding to the repeating “1” in the ans variable. Or 1 1 0 1 0 1 1. Whichever is easier to program. How do I do this?
댓글 수: 0
채택된 답변
Rohit Kulkarni
2022년 7월 7일
I think this may work:
A = [3 3 2 1 5 1 0 4];
[uniqueA i j] = unique(A,'first');
idRep = find(not(ismember(1:numel(A),i)))
rep_var = A(idRep)
ll = ismember(A,rep_var)
추가 답변 (1개)
Jon
2022년 7월 7일
x = [3 2 1 5 1 4 0]
L = x == 1
댓글 수: 5
Jon
2022년 7월 7일
편집: Jon
2022년 7월 7일
That's fine as long as you have a solution, but I'm puzzled, as to why you would have array bounds errors, when as you can see it ran without issues in the small example I show above. As you had an array bounds error, are you sure you used :
[N,edges,bin]= histcounts(x,[u,u(end)+1])
and not:
[N,edges,bin]= histcounts(x,[u,u(end+1)])
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!