Display value of variable

您所在的位置:网站首页 values函数matlab Display value of variable

Display value of variable

2023-05-30 18:54| 来源: 网络整理| 查看: 265

Open Live Script

Here are three ways to display multiple variable values on the same line in the Command Window.

Concatenate multiple character vectors together using the [] operator. Convert any numeric values to characters using the num2str function. Use disp to display the result.

name = 'Alice'; age = 12; X = [name,' will be ',num2str(age),' this year.']; disp(X)Alice will be 12 this year.

Use sprintf to create text, and then display it with disp.

name = 'Alice'; age = 12; X = sprintf('%s will be %d this year.',name,age); disp(X)Alice will be 12 this year.

Use fprintf to directly display the text without creating a variable. However, to terminate the display properly, you must end the text with the newline (\n) metacharacter.

name = 'Alice'; age = 12; fprintf('%s will be %d this year.\n',name,age);Alice will be 12 this year.


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3