way to pull information from matrix - if X then store Y, but only if Y is not the last number in the column?

Hi,
I'm looking to pull information from a matrix with an if statement. But when the if statement is true, only to pull the information if it is not the last row in the matrix. Is there a way to do this?
So for example, if column one is made up of 1's and 0's, I want it to store the information from the corresponding row's column two only when column one shows 1's, and only when it is not the last entry in the matrix.
Thanks in advance to any help offered.
Mamie

 採用された回答

dpb
dpb 2015 年 8 月 19 日
ix=x(1:end-1,1)==1; % all except last if 1
z=x(ix,2); % pick those up
Can, of course, eliminate the intermediate variable; just wrote as separate step to make easier to read without the additional level of indexing--
z=x(x(1:end-1,1)==1,2);
Moral: if the last row can't ever contribute to the result, throw it away from the start...

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

質問済み:

2015 年 8 月 19 日

コメント済み:

2015 年 8 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by