Cross product of two tables without common key

조회 수: 8 (최근 30일)
Frederick Awuah-Gyasi
Frederick Awuah-Gyasi 2022년 5월 21일
댓글: Frederick Awuah-Gyasi 2022년 5월 23일
tables 1
Name
A
B
C
table2
Number Count
1 0
2 0
3 0
4 0
I want
Name Number Count
A 1 0
A 2 0
A 3 0
A 4 0
B 1 0
B 2 0
B 3 0
B 4 0
C 1 0
C 2 0
C 3 0
C 4 0
I tried outer join but since there is not key between the two tables that failed. Any help. Thank you.
  댓글 수: 1
Star Strider
Star Strider 2022년 5월 22일
This may not be at all relevant, however Three columns (x,y,z) in table, Loop through table for each X plot Y vs Z could tangetially be related to this post.
I have no idea if it is or what the desired results are.

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2022년 5월 21일
편집: Voss 2022년 5월 21일
table1 = table(["A";"B";"C"],'VariableNames',{'Name'})
table1 = 3×1 table
Name ____ "A" "B" "C"
table2 = table([1;2;3;4],[0;0;0;0],'VariableNames',{'Number','Count'})
table2 = 4×2 table
Number Count ______ _____ 1 0 2 0 3 0 4 0
[ii,jj] = meshgrid(1:height(table1),1:height(table2))
ii = 4×3
1 2 3 1 2 3 1 2 3 1 2 3
jj = 4×3
1 1 1 2 2 2 3 3 3 4 4 4
new_table = [table1(ii,:) table2(jj,:)]
new_table = 12×3 table
Name Number Count ____ ______ _____ "A" 1 0 "A" 2 0 "A" 3 0 "A" 4 0 "B" 1 0 "B" 2 0 "B" 3 0 "B" 4 0 "C" 1 0 "C" 2 0 "C" 3 0 "C" 4 0
  댓글 수: 2
dpb
dpb 2022년 5월 22일
Cute! :)
Frederick Awuah-Gyasi
Frederick Awuah-Gyasi 2022년 5월 23일
@_ Worked Perfectly. Thank you so much.
@Star Strider this helped me replace missing data points in out prevous discussion really appreciate all you help.
Thanks @dpb

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

dpb
dpb 2022년 5월 21일
May be something more exotic, but I'd just build it from the pieces...
tT=[table(reshape(repmat(t1.Name,1,height(t2)).',[],1),'VariableNames',{'Name'}) repmat(t2,height(t1),1)]
tT =
12×3 table
Name Number Count
____ ______ _____
A 1 0
A 2 0
A 3 0
A 4 0
B 1 0
B 2 0
B 3 0
B 4 0
C 1 0
C 2 0
C 3 0
C 4 0
>>

카테고리

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