find an ID that has two values for another variable

2 ビュー (過去 30 日間)
joseph Frank
joseph Frank 2013 年 8 月 23 日
Hi, ID and fyear are vectors of the same size year(x00-1)=1996;year(x00-7)=1990 I want to find the ID that is equal to ID(i) but has for fyear values of 1990 and 1996. Initially I wrote:
x0=find(ID=ID(i) & fyear==year(x00-1) & fyear==year(x00-7))) but x0 was always empty and I figured out that the code was wrong because when the logical for fyear=1990 is 1 it is 0 for fyear=1996 and vice versa. How can I write a code to say I want the ID which is equal to ID(i) and that ID has a fyear values of 1990 and 1996

採用された回答

Iain
Iain 2013 年 8 月 23 日
x0 = find(ID = ID(i) & (fyear == year(x00-1) | fyear==year(x00-7)))
Note that | is "pipe", not capital i, or lowercase L.

その他の回答 (1 件)

joseph Frank
joseph Frank 2013 年 8 月 23 日
No I want them both to exist the 1990 and 1996 . It is not an "or " but rather an also.
  2 件のコメント
Iain
Iain 2013 年 8 月 23 日
Try the code I gave you. The year cannot be BOTH, it must be one and/or the other.
The logic gate "or", is and/or, it is not exlusively one or the other [exclusively one or the other is an "exclusive or"].
Iain
Iain 2013 年 8 月 23 日
Actually, re-reading your code, are you actually trying to get the ID values that exist in both years? - A very different question.
intersect(ID(fyear == year(x00-1)),ID(fyear == year(x00-7)))

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

カテゴリ

Help Center および File ExchangeFinancial Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by