Replace Header & Append new row in writetable
    조회 수: 6 (최근 30일)
  
       이전 댓글 표시
    
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!!
댓글 수: 0
채택된 답변
  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.
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

