关闭细胞阵列的尺寸-为什么?

时间:2018-12-11 20:27:53

标签: matlab cell-array

代码给我错误

  

数组的维数为   级联不一致。

那是为什么?我创建了一个具有不同长度的不同字符串单元格的单元格数组,这不是问题,例如可以正常工作。

test = {'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'b' 'a' 'ddddddddddasdfasdfasdfadsfb' 'a' 'bdd'}


Questions = {'Constant' 'The teacher shows an interest in every student''s learning' 
    'There is noise and disorder' 'Number of class periods per week in the test language'
    'Number of class periods per week in mathematics' 'Number of class periods per week in science'
    'Number of books at home' 'Having Desktop Computer' 'Having a Notebook' 'Having a Tablet' 'Having a Console' 'Having an eReader'};

1 个答案:

答案 0 :(得分:4)

您必须将ellipses放在每行的末尾,以使horizontal concatenation正确地继续:

Questions = {'Constant' 'The teacher shows an interest in every student''s learning' ...
             'There is noise and disorder' 'Number of class periods per week in the test language' ...
             'Number of class periods per week in mathematics' 'Number of class periods per week in science' ...
             'Number of books at home' 'Having Desktop Computer' 'Having a Notebook' 'Having a Tablet' 'Having a Console' 'Having an eReader'};

在没有省略号的情况下,MATLAB会解释到下一行的移动,就好像您放置了分号(即vertical concatenation)一样,将后续值放在下一行中。对于您而言,最终将垂直连接不同长度的行,从而导致尺寸不匹配错误。