Replace Header & Append new row in writetable

6 ビュー (過去 30 日間)
chlor thanks
chlor thanks 2021 年 5 月 4 日
編集済み: chlor thanks 2021 年 5 月 4 日
I have a cell array say
testarray={'1 2 3'; '3 4 5'}
And desired header to be
col1 col2 col3
How do I write table in excel that looks like this
col1 col2 col3
1 2 3
3 4 5
Thank you!!

採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 5 月 4 日
編集済み: Scott MacKenzie 2021 年 5 月 4 日
testarray={'1 2 3'; '3 4 5'}
z = split(testarray);
T = array2table(z)
T.Properties.VariableNames = { 'col1', 'col2', 'col3' }
T =
2×3 table
col1 col2 col3
_____ _____ _____
{'1'} {'2'} {'3'}
{'3'} {'4'} {'5'}
Or, if you want a table of numeric data:
testarray={'1 2 3'; '3 4 5'}
z = split(testarray);
s = string(z);
d = double(s);
T = array2table(d)
T.Properties.VariableNames = { 'col1', 'col2', 'col3' }
T =
2×3 table
col1 col2 col3
____ ____ ____
1 2 3
3 4 5
There might be some tricks to trim down the code, not sure.
  1 件のコメント
chlor thanks
chlor thanks 2021 年 5 月 4 日
編集済み: chlor thanks 2021 年 5 月 4 日
Thank you Scott!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by