将单元格数组中的单元格转换为单元格数组 - matlab

时间:2012-08-29 23:45:02

标签: matlab cell-array

不要对数组中的行号感到困惑。我只是要求将1转换为样式2

这是Cell Array C

cell array 1

我想将它转换为以下版本我该怎么做?

V2 =

cell array 1 converted to v2 enter image description here

1 个答案:

答案 0 :(得分:2)

如果我理解正确,你有一个扁平的字符串数组(包含有效的MATLAB单元数组定义),并且你想将每个字符串转换为它自己的子单元格数组。所以你需要的是:

cellfun(@eval, C, 'UniformOutput', false)

其中C是字符串的原始单元格数组。

示例:

C = {'{''samsung'', ''n150'', ''jp0xtr'', ''n570''};'; ...
    '{''samsung'', ''n150'', ''jp0xtr'', ''beyaz''};'}
C2 = cellfun(@eval, C, 'UniformOutput', false)

结果是:

C = 

    '{'samsung', 'n150', 'jp0xtr', 'n570'};'
    '{'samsung', 'n150', 'jp0xtr', 'beyaz'};'


C2 = 

    {1x4 cell}
    {1x4 cell}