Using "or" operands when indexing a matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all,
I am trying to speed up a for loop that I have by using indexing instead of "if" statements. To that end I have the following line of code:
idx = find ((MouseData(k).BehaviourData(:,4) == NovMouse) || (MouseData(k).BehaviourData(:,5) == NovMouse) || (MouseData(k).BehaviourData(:,6) == NovMouse));
However when I run it, I get the following error:
Operands to the || and && operators must be convertible to logical scalar values.
It is worthy of noting that NovMouse is a scalar value, as is MouseData(k).BehaviourData(:,4).
Alternatively, I would appreciate any alternatives to this code that wouldn't take too long run.
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 5월 20일
If operands are arrays then use single (|) instead of (||)
idx = find ((MouseData(k).BehaviourData(:,4) == NovMouse) | (MouseData(k).BehaviourData(:,5) == NovMouse) | (MouseData(k).BehaviourData(:,6) == NovMouse));
추가 답변 (0개)
참고 항목
카테고리
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!