Expand a table to match number of rows of an other table

조회 수: 5 (최근 30일)
Luca
Luca 2021년 5월 16일
댓글: Luca 2021년 5월 16일
Hi,
I have a table T with dimension 1*2. The first column is month and the second year.
For example
month year
1 2016
Then I have a table ID with dimension x*1.
It looks like this
ID
10000
10001
10002
10003
.
.
.
Right now I want assign the value of table T to all rows of table ID. It should look like this
ID month year
10000 1 2016
10001 1 2016
10002 1 2016
. . .
. . .
. . .
I will need this code in a loop where ID can change size in every iteration so it should be able to be flexible.
I there a way to do that?
Thank you in advance.

채택된 답변

Walter Roberson
Walter Roberson 2021년 5월 16일
month = 1;
year = 2016;
ID = [10000
10001
10002
10003];
t1 = table(month,year)
t1 = 1×2 table
month year _____ ____ 1 2016
t2 = table(ID)
t2 = 4×1 table
ID _____ 10000 10001 10002 10003
t3 = [t2, repmat(t1, height(t2),1)]
t3 = 4×3 table
ID month year _____ _____ ____ 10000 1 2016 10001 1 2016 10002 1 2016 10003 1 2016

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by