Join tables using all rows of a column and fulling with zeros when not found a value
조회 수: 1 (최근 30일)
이전 댓글 표시
Montserrat Vallcorba Martí
2017년 10월 27일
댓글: Montserrat Vallcorba Martí
2017년 10월 27일
I have two tables, for example:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168847/image.jpeg)
And I want to join the tables having all values of 'Ind' and 'Date' for each 'Code', fulling with zero when it doesn't find a value:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168849/image.jpeg)
How can I do this?
Thank you!
댓글 수: 0
채택된 답변
Andrei Bobrov
2017년 10월 27일
편집: Andrei Bobrov
2017년 10월 27일
T1 = readtable('20171027.xls','Range','A2:B14');
T2 = readtable('20171027.xls','Range','A16:D31');
T1.Date = datetime(T1.Date);
T2.Date = datetime(T2.Date);
[g,v] = findgroups(T2.Code);
n = max(g);
T3 = repmat(T1,n,1);
T3.Code = v(kron((1:n)',ones(size(T1,1),1)));
T3 = T3(:,[3,1:2]);
[lo,ii] = ismember(T3,T2(:,1:3));
T3.Value = zeros(size(T3,1),1);
T3.Value(lo) = T2.Value(ii(lo));
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!