简体   繁体   中英

making a Table in Matlab

I'm trying to make a table in Matlab and initialze it with zeros so I did it in this way:

z =zeros(4,4);
exTab = table(z,'RowNames',{'row1' 'row2' 'row3' 'row4' }, 'VariableNames',{'column','column2','column3','column4'}) 

and I received this error

The VariableNames property must contain one name for each variable in the table

it recognizes all columns of the zeros as just one column, how to do it in the right way?

Use array2table instead of table . ie

z = zeros(4,4);
exTab = array2table(z,'RowNames',{'row1','row2','row3','row4'},...
    'VariableNames',{'column1','column2','column3','column4'});

This, as expected, gives:

>> exTab
exTab =
  4×4 table
            column1    column2    column3    column4
            _______    _______    _______    _______
    row1       0          0          0          0   
    row2       0          0          0          0   
    row3       0          0          0          0   
    row4       0          0          0          0   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM