haibaraxx的个人博客分享 http://blog.sciencenet.cn/u/haibaraxx

博文

Matlab: input & fprintf

已有 3469 次阅读 2016-8-19 05:13 |个人分类:Matlab|系统分类:科研笔记| input, fprintf, formatSpec

Syntax: input_user1 = input('Please input your number: ');

In the Command Window you will be asked: Please input your number:

Then you can input a number such as 2.

Syntax: input_user2 = input('Please input your name: ','s');  % your input is a string.

In the Command Window you will be asked: Please input your name:

Then you can input a name string such as David.


Syntax: fprintf('Thank you for inputting your name n');  % n gives a new line.

Output: Thank you for inputting your name


More about fprintf:

Syntax: fprintf(formatSpec,A1,A2,...)

% formatSpec specified as a character vector containing formatting operators.

Formatting Operator

A formatting operator starts with a percent sign, %,and ends with a conversion character. The conversion character is required. Optionally, you can specify identifier, flags, field width,precision, and subtype operators between % and the conversion character. (Spaces are invalid between operators andare shown here only for readability).


e.g. %d ->科学计数法形式; %.2f->floting-point number with 2 digits after the decimal point; %5.2f-> 5 sapces (width=5) for the floting-point number with 2 digits after the decimal point.



% what if you forget or add one variable?


% display % (with %%), (with \) and ' (with '')



https://blog.sciencenet.cn/blog-3031432-997321.html

上一篇:Matlab: list folder contents
下一篇:Matlab: if statement
收藏 IP: 134.1.1.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-10-20 07:21

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部