MATLAB: Problem getting correct indices of a matrix

indexingMATLABvectors

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!

Best Answer

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..
Related Question