我是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(line 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(零(0,20), ' VariableNames' {" C1"" C2"" C3"" C4"" C5"" C6"" C7"" C8"" C9"" C10&#34 ;, " C11"" C12"" C13"" C14"" C15"" C16& #34;" C17"" C18"" C19"" C20"},' RowNames&#39 ;, {1:800});
答案 0 :(得分:0)
试试这个:
% 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);