Append column given a 'year' condition

I have a cell type variable A with 30000 rows and 29 columns, for example:
b1 *b2* b3 b4 b5 b6 b7 ...
A={7 1999 28,14 1388 33 78 39021
8 2002 44,44 150 4 56 60012
12 2002 54,46 100 21 49 40701
13 1998 46,41 189 22 44 30901...}.
Column b2 gives different years. I am trying to a ppend a new column that, for example, gives 1 if the year in b2 is after 2000 and 0 if the year in b2 is before 2000 . For instance in this example I would get:
b1 *b2* b3 b4 b5 b6 b7 ... b30
A={7 1999 28,14 1388 33 78 39021 0
8 2002 44,44 150 4 56 60012 1
12 2002 54,46 100 21 49 40701 1
13 1998 46,41 189 22 44 30901... 0}.
Can someone help me please? Thank you.

2 件のコメント

José-Luis
José-Luis 2014 年 9 月 2 日
Is A a cell array?
Maria
Maria 2014 年 9 月 2 日
yes.

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

 採用された回答

Guillaume
Guillaume 2014 年 9 月 2 日
編集済み: Guillaume 2014 年 9 月 2 日

2 投票

A(:, end+1) = num2cell([A{:, 2}] >= 2000);

2 件のコメント

Guillaume
Guillaume 2014 年 9 月 2 日
However, if you only have numbers in your cell array, why aren't you using a matrix? It makes manipulation much easier
A = cell2mat(A);
A(:, end+1) = A(:, 2) >= 2000;
Maria
Maria 2014 年 9 月 2 日
you are right. Thanks

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

その他の回答 (1 件)

José-Luis
José-Luis 2014 年 9 月 2 日

1 投票

A = num2cell(1995 + randi(10,[20 1]));
A(:,end+1) = num2cell( cell2mat(A) >= 2000)

カテゴリ

ヘルプ センター および File ExchangeLanguage Fundamentals についてさらに検索

製品

質問済み:

2014 年 9 月 2 日

コメント済み:

2014 年 9 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by