为什么strcat(mystring)与mystring不同?

jak*_*kub 2 matlab

[~, currenthost] = system('hostname');
table({currenthost}, 'VariableNames', {'host'})
Run Code Online (Sandbox Code Playgroud)

ans = 

       host   
    __________

    [1x9 char]
Run Code Online (Sandbox Code Playgroud)

在做的时候

[~, currenthost] = system('hostname');
table({strcat(currenthost)}, 'VariableNames', {'host'})
Run Code Online (Sandbox Code Playgroud)

ans = 

       host   
    _________

    'my-hostt'
Run Code Online (Sandbox Code Playgroud)

为什么?

And*_*uri 6

实际差异小于您的想法.

strcat删除尾随空格.你的currenthost变量是'my-hosttt '(注意最后的空格).当你打电话strcat说最后一个空格被删除.

巧合的是,MATLAB限制显示表中的字符是9,所以如果有一个长度为8的字符串,它将显示字符串本身,如果它更长,它只会告诉你它的长度!

长话短说:它们是同一类型,性格较少.由于长度,MATLAB只是以不同方式显示它们.