Replace Header & Append new row in writetable

3 Ansichten (letzte 30 Tage)
chlor thanks
chlor thanks am 4 Mai 2021
Bearbeitet: chlor thanks am 4 Mai 2021
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!!

Akzeptierte Antwort

Scott MacKenzie
Scott MacKenzie am 4 Mai 2021
Bearbeitet: Scott MacKenzie am 4 Mai 2021
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.

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by