Code to repeat rows multiple times

62 ビュー (過去 30 日間)
BA
BA 2022 年 7 月 14 日
コメント済み: BA 2022 年 7 月 15 日
I have some data with data that I want to repeat for a total for a total of three times. Essentially, the table is a 2343x1 table and I want every date to repeat three times so the table becomes a 7029x1 table. Unfortunately, the dates aren't exactly in order (a few days are skipped) so I can't create code to write a different table from the one I have and just code it to be repeats. I specifically need every row in the table to be duplicated twice (so there are 3 instances of each date).
If any part of this is confusing, let me know but I have attached an example of basically what I want the dates to look like. It should make more sense once you see the stuff below
%Table before
table = ['1/12/22';'1/13/22';'1/14/22']
table = 3×7 char array
'1/12/22' '1/13/22' '1/14/22'
%Table after
new_table = ['1/12/22';'1/12/22';'1/12/22';'1/13/22';'1/13/22';'1/13/22';'1/14/22';'1/14/22';'1/14/22']
new_table = 9×7 char array
'1/12/22' '1/12/22' '1/12/22' '1/13/22' '1/13/22' '1/13/22' '1/14/22' '1/14/22' '1/14/22'

採用された回答

Torsten
Torsten 2022 年 7 月 14 日
table = ['1/12/22';'1/13/22';'1/14/22']
table = 3×7 char array
'1/12/22' '1/13/22' '1/14/22'
new_table = repelem(table,3,1)
new_table = 9×7 char array
'1/12/22' '1/12/22' '1/12/22' '1/13/22' '1/13/22' '1/13/22' '1/14/22' '1/14/22' '1/14/22'
  1 件のコメント
BA
BA 2022 年 7 月 15 日
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by