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 件)
Andrei Bobrov
2014 年 8 月 12 日
c = cell2mat(A(:,4));
A(:,6) = num2cell(B(ismember(B(:,2),c),3));
0 件のコメント
参考
カテゴリ
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!