|||
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 '')
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-15 16:22
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社