%数值的格式化输出
str_a=sprintf('%.5f',pi);
%字符串的格式化输出
str=sprintf('pi = %.5f',pi); %输出类型为char
str1=sprintf(string('pi = %.5f'),pi); %输出类型为string
team1='Manchester United';
team2='Chelsea';
str2=sprintf('%s won %s,congratulations',team1,team2);
输出
>>str_a
str_a =
3.14159
>> str
str =
pi = 3.14159
>> str1
str1 =
string
"pi = 3.14159"
>> str2
str2 =
Manchester United won Chelsea,congratulations
参考链接:https://blog.csdn.net/kaever/article/details/70207380
参考链接:https://zhidao.baidu.com/question/1306539527253145779.html