Substitute blank entries in a cell array by elements from a double matrix

조회 수: 6 (최근 30일)
I have a cell type variable A with 500 rows and 3 columns:
c1 y v c1 c2 c3
A={13 1999 47,7 13 183 [] [] 0
141 1999 60,2 141 308 [] [] 0
174 1999 51,9 174 308 [] [] 0
181 1999 52,9 181 183 [] [] 0}
And I have a double variable B with 2000 rows and 3 columns:
y c1 c3
B=[1999 13 32
1999 67 189
1999 140 40
1999 141 55
1999 143 53
1999 174 38
1999 177 63
1999 181 30
1999 185 51]
If the first column of A matches the second column of B (if the c1s match in A and B) then I would like to substitute the blank entries [ ] in the sixth column of A (c3) by the values of the third column of B (c3). So my new A:
A={13 1999 47,7 13 183 32 [] 0
141 1999 60,2 141 308 55 [] 0
174 1999 51,9 174 308 38 [] 0
181 1999 52,9 181 183 30 [] 0}
Thank you

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 12일
편집: Azzi Abdelmalek 2014년 8월 12일
A={13 1999 47.7 13 183 [] [] 0
141 1999 60.2 141 308 [] [] 0
174 1999 51.9 174 308 [] [] 0
181 1999 52.9 181 183 [] [] 0}
B=[1999 13 32
1999 67 189
1999 140 40
1999 141 55
1999 143 53
1999 174 38
1999 177 63
1999 181 30
1999 185 51]
[ii,jj]=ismember(B(:,2),[A{:,1}]')
A(nonzeros(jj),6)=num2cell(B(ii,3))

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 8월 12일
c = cell2mat(A(:,4));
A(:,6) = num2cell(B(ismember(B(:,2),c),3));

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by