problem getting correct indices of a matrix

1 回表示 (過去 30 日間)
Christopher
Christopher 2014 年 10 月 10 日
コメント済み: Christopher 2014 年 10 月 10 日
I have the code:
odif = find(o~=on); % element index: combos with O==O
pdif = find(p(odif)~=pn(odif)); % element index: combos with O==O and P~=P
psam = find(p(odif)==pn(odif)); % element index: combos with O==O and P==P
where o, on, p, and pn, are equal size matrices. odif is found correctly. The code is supposed to get a vector of indices (odif) where elements in o and on are different. So far, so good.
Then, AMONG those elements o(odif), find the elements for which p and pn are different (pdif) or equal (esam). The problem is that pdif and psam return the indices for the vector odif, and NOT the indices for the the matrices o1/o1n/p1/p1n. How do I change this, so that I get the indices for the matrices and not the vector odif? Thank you!

採用された回答

Andrew Reibold
Andrew Reibold 2014 年 10 月 10 日
編集済み: Andrew Reibold 2014 年 10 月 10 日
Try this maybe?
odif = find(o~=on); % element index: combos with O==O
pdif = odif(find(p(odif)~=pn(odif))); % element index: combos with O==O and P~=P
psam = odif(find(p(odif)==pn(odif))); % element index: combos with O==O and P==P
No time to test..
  1 件のコメント
Christopher
Christopher 2014 年 10 月 10 日
looks like that works, thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by