필터 지우기
필터 지우기

Substitute blank entries by 1 or 0 in a column of a cell given a condition.

조회 수: 2 (최근 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.

채택된 답변

Andrei Bobrov
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개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by