MATLAB分区单元阵列

时间:2017-06-29 13:25:39

标签: arrays string matlab cell

我有一个单元格数组,长度为128个字符,即

private void ItemsControl_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
        TextBox textBox = Keyboard.FocusedElement as TextBox;
        if (textBox != null)
        {
            textBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
        }
    }
}

我想做的是从左边开始将它分成8块,然后将每个8块块放入一个新的单元阵列中。最简单的方法是什么?

3 个答案:

答案 0 :(得分:4)

你可以用一行

来做
mycell = repelem('a', 128); % creating the cell

newcells = cellstr(reshape(mycell{:},8,[])'); % cells with 8 characters each

如果您的单元格只有1x1,则包含128个字符。

答案 1 :(得分:1)

valS = 1;
valE = 8;

for ii=1:(128/8)
   newC{ii,:} = c{valS:valE};
   valS = valE + 1; % after first loop valS = 9 ...
   valE = valE + 8; % after first loop valE = 16 ...
end

如果你想将newC完全分成不同的变量,你也可以使用eval

答案 2 :(得分:0)

以下情况如何?

res = cell(1,16);
for ii=0:15
    res{ii} = c{1}((1:8)+ii*8);
end