Matlab:转换为字符串的单元格

时间:2015-12-03 08:29:18

标签: string matlab cell

问题:我有包含char的单元格的postfix(137x25)单元格(Ex postfix(6,8)= postfix {6,8} {1,1}< 1x3char>)。我想在(137x25)char的单元格中进行转换。

以这种方式创建Postfix:

numIndex = cellfun('isclass', postfix, 'double');
  tmpStr = sprintf('%g;', postfix{numIndex});
  postfix(numIndex) = dataread('string', tmpStr, '%s', 'delimiter', ';');

我尝试过不同的解决方案:

解决方案1 ​​

postfix(cellfun(@isempty,postfix))={''};

解决方案2

postfix(cellfun(@isnumeric, postfix)) =  cellfun(@(x) sprintf('%.5f', x), postfix(cellfun(@isnumeric, postfix)), 'UniformOutput', false)

解决方案3

char(postix)

解决方案4

我尝试使用

br

此解决方案的任何人都在(137x25 char数组)中转换postfix。你能给我其他想法吗?

2 个答案:

答案 0 :(得分:1)

您想循环遍历单元格数组后缀的每个元素,并用其内容替换单元格数组(单元格数组本身)的每个元素。使用cellfun替换循环,您可以写:

postfix = cellfun(@(x)x{1}, postfix, 'UniformOutput', false);

答案 1 :(得分:0)

我也用这种方式解决了这个问题

Probe