Using "or" operands when indexing a matrix

1 回表示 (過去 30 日間)
Amy Hassett
Amy Hassett 2020 年 5 月 20 日
コメント済み: Ameer Hamza 2020 年 5 月 20 日
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.

採用された回答

Ameer Hamza
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));
  2 件のコメント
Amy Hassett
Amy Hassett 2020 年 5 月 20 日
thanks!
Ameer Hamza
Ameer Hamza 2020 年 5 月 20 日
I am glad to be of help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by