将字符串列附加到数字列

时间:2014-02-26 19:29:48

标签: string matlab concatenation cell-array

如何在MATLAB中将一列字符串附加到数字列?

例如,我有字符串列wrds和数字列occurs

wrds={'the' 'of' 'to' 'and'}'; occurs=[103 89 55 20]';

我希望将它们并排放置,以便它们显示如下:

'the' 103
'of'   89
'to'   55
'and'   20

你会想到这会解决问题:

out={wrds occurs}

但是当我输入它时我得到的输出是:

out =
{4x1 cell}    [4x1 double]

这没告诉我什么。我该怎么做才能看到字符串和数字的实际显示?

1 个答案:

答案 0 :(得分:2)

将数值数组转换为单元格数组并连接:

>> out = [wrds(:) num2cell(occurs)]
out = 
    'the'    [103]
    'of'     [ 89]
    'to'     [ 55]
    'and'    [ 20]

作为num2cell的更快速替代方案,我建议sprintfcout = [wrds(:) sprintfc('%d',occurs(:))]