如何在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]
这没告诉我什么。我该怎么做才能看到字符串和数字的实际显示?
答案 0 :(得分:2)
将数值数组转换为单元格数组并连接:
>> out = [wrds(:) num2cell(occurs)]
out =
'the' [103]
'of' [ 89]
'to' [ 55]
'and' [ 20]
作为num2cell
的更快速替代方案,我建议sprintfc
:out = [wrds(:) sprintfc('%d',occurs(:))]
。