Substitute blank entries by 1 or 0 in a column of a cell given a condition.
1 回表示 (過去 30 日間)
古いコメントを表示
I have a double variable A with 3 columns and 90000 rows, sorted first by a1(year) and then by a2 (code); and a cell variable B with 10 columns and about 3000 rows, sorted by b2 (year) and then by b1 (code). For example:
a1 a2 a3
A=[2001 7 3
2001 55 2
2002 9 4
2002 12 1
2002 24 3
2003 13 5…]
b1 b2 b3 b4 b5 b6 b7 b8 b9 b10
B={7 2001 28,14 [] 1388 33 [] [] [] []
8 2002 44,44 [] 150 [] [] [] [] []
12 2002 54,46 [] 100 21 49 40701 [] []
13 2003 46,41 [] 189 22 44 30901 [] []..}.
If a1 matches b2 (years) and a2 matches b1 (codes), I would like to substitute the blank entries in b9 of B by 1 if the value of c3 is higher than 1 and zero if the value of c3 is 1. So my B would then be:
b1 b2 b3 b4 b5 b6 b7 b8 b9 b10
B={7 2001 28,14 [] 1388 33 [] [] 1 []
8 2002 44,44 [] 150 [] [] [] [] []
12 2002 54,46 [] 100 21 49 40701 0 []
13 2003 46,41 [] 189 22 44 30901 1 []..}.
Could someone help me? Thank you.
2 件のコメント
採用された回答
Andrei Bobrov
2014 年 8 月 21 日
b1 = cell2mat(B(:,[2 1]));
[i0,i1] = ismember(b1,A(:,1:2),'rows');
B(i0,10) = num2cell(A(i1(i0),3) > 1);
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!