在 Matlab 中制作 Table

making a Table in Matlab

我试图在 Matlab 中制作一个 table 并用零初始化它,所以我是这样做的:

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

我收到了这个错误

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

它将零的所有列都识别为一列,如何以正确的方式做到这一点?

使用array2table instead of table。即

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

如预期的那样,给出:

>> 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