0

我是 Matlab 的新手,所以我遇到了一个问题,我需要创建具有某些行和列名称的表。

CameraCar = array2table(zeros(0,20), 'VariableNames',{"c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12","c13","c14","c15","c16","c17","c18","c19","c20"},'RowNames',{1:800});

我尝试在代码上使用上面的代码,但在创建它时出现错误(如下所述)。

使用 matlab.internal.tabular.private.rowNamesDim/validateAndAssignLabels 时出错(第 109 行) RowNames 属性必须是一个元胞数组,每个元素都包含一个非空字符向量。

matlab.internal.tabular.private.tabularDimension/setLabels 中的错误(第 173 行)obj = obj.validateAndAssignLabels(newLabels,indices,fullAssignment,fixDups,fixEmpties,fixIllegal);

matlab.internal.tabular.private.tabularDimension/createLike_impl 中的错误(第 355 行)obj = obj.setLabels(dimLabels,[]);

matlab.internal.tabular.private.tabularDimension/createLike 错误(第 62 行)obj = obj.createLike_impl(dimLength,dimLabels);

表格/initInternals 中的错误(第 206 行) t.rowDim = t.rowDim.createLike(nrows,rowLabels);

table.init 中的错误(第 327 行) t = initInternals(t, vars, numRows, rowLabels, numVars, varnames);

array2table 中的错误(第 64 行) t = table.init(vars,nrows,rownames,nvars,varnames);

CarMatrix 中的错误(第 1 行)CameraCar = array2table(zeros(0,20), 'VariableNames',{"c1","c2","c3","c4","c5","c6","c7" ,"c8","c9","c10","c11","c12","c13","c14","c15","c16","c17","c18","c19"," c20"},'行名',{1:800});

4

1 回答 1

1

试试这个:

% Get your row numbers (optional as the table already gives these numbers
% as default)
rowNumbers = 1:1:800;
% Convert to cellarray
myCellArray = num2cell(rowNumbers);
% Convert numbers to strings
myCellArray = cellfun(@num2str, myCellArray, 'UniformOutput', false);
% Set up table
CameraCar = array2table(zeros(800,20), 'VariableNames',{'c1','c2','c3','c4','c5','c6','c7',...
    'c8','c9','c10','c11','c12','c13','c14','c15','c16','c17','c18','c19','c20'},'RowNames',myCellArray);
于 2018-03-04T22:01:51.577 回答