Substitute blank entries in a cell array by elements from a double matrix
1 次查看(过去 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
0 个评论
采纳的回答
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))
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!