2, 1, and 6 are the first 3 elements of the double array A and I want only them to be 1 in the resulting logical array B (and zero for the rest).
converting a double array to a logical array conditionally
조회 수: 1 (최근 30일)
이전 댓글 표시
Double array A is [2 1 6 7 3 5 4]. How can I convert it to a logical array in a way to get 1 for the first (for example) 3 elements and 0 for the rest. i.e., B = [1 1 0 0 0 1 0]. I apologize for the very basic nature of this question but unfortunately couldn't find any answer for it!
채택된 답변
Andrei Bobrov
2015년 6월 16일
편집: Andrei Bobrov
2015년 6월 16일
A = [2 1 6 7 3 5 4];
B = ismember(sort(A),A(1:3));
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!