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!