将字符串列追加到数字列



如何在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]

这什么也没告诉我。 如何执行此操作才能看到字符串和数字的实际显示?

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

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

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

最新更新