我是 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行)属性必须是单元格数组,每个 元素包含一个非空字符向量。
matlab.internal.tabular.private.tabularDimension/setLabels 中的错误 (第 173 行) obj = obj.validateAndAssignLabels(newLabels,indices,fullAssignment,fixDups,fixEmptyties,fixIllegal);
中的错误 matlab.internal.tabular.private.tabularDimension/createLike_impl (line 355) obj = obj.setLabels(dimLabels,[]);
matlab.internal.tabular.private.tabularDimension/createLike 中的错误 (第 62 行) obj = obj.createLike_impl(dimLength,dimLabels);
表格/初始化内部错误(第 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), '变量名称',{"c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12","c13","c14","c15","c16","c17","c18","c19","c20"},'RowNames',{1:800});
试试这个:
% 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);