当前位置:网站首页>Matlab rounding
Matlab rounding
2022-06-25 01:18:00 【The sheep said it was okay】
One 、 Integral function
1. Round to zero ( To round off )
fix- Round to zero (Round towards zero);
fix(3.6)
ans = 3
2. Rounding negative infinity ( No more than x Maximum integer for - Gauss rounding )
floor- Rounding negative infinity (Round towards minus infinity);
floor(-3.6)
ans = -4
3. Rounding to positive infinity ( Greater than x Minimum integer of )
ceil- Rounding to positive infinity (Round towards plus infinity);
ceil(-3.6)
ans = -3
4. Round to the nearest integer , rounding ( Round to the nearest whole )
round- Round to the nearest integer , rounding (Round towards nearest integer);
round(3.5)
ans = 4
Two 、 Round to a certain place after the decimal point , Keep a few decimal places , It's often used .
1. Numerical type roundn— Round any bit position
a=123.4567890;
a=roundn(a,-4)
a = 123.4568
among roundn The functions are as follows :
y = ROUNDN(x) rounds the input data x to the nearest hundredth. % Don't specify n, To the hundredth y = ROUNDN(x,n) rounds the input data x at the specified power % The number of digits specified after the decimal point n
2. Semiotic type
digits(4)
vpa(…)
Must explain :vpa The command does not recognize integers and decimals , Just the total number of digits , So for it, decimal and integer numbers occupy one place , For example 9.3154 If you keep two decimal places, you have to write :
a=9.3154;
digits(3)
b=vpa(a)
b= 9.32
among b Is a symbolic variable ;
3. Character
a=12.34567;
b = fprintf(‘%8.2f’,a)
b = 12.35 among b Is a character variable .
matlab Text output
Two functions :disp fprintf
1、 function disp With just one variable , It can be a conceited matrix or a numerical matrix , To output a simple text message , Just enclose the information in single quotation marks :
disp(‘my favorite color is red’);
perhaps
yourname=input(‘enter your name’,‘s’);
disp([‘your name is’,youname]);
for example
yourname = input('enter your name ',‘s’);
enter your name panrq
disp(['your name is ',yourname]);
your name is panrq
When selecting text information with numeric variable values , You need to use the function num2str Convert the type of numeric variable to character type
x=98;
outstring = ['x = ',num2str(x)];
disp(outstring);
x = 98
disp(['x = ',num2str(x)]);
x = 98
disp Function can only take one variable , The columns in the table need to be combined into a matrix , As shown in the following procedure .
x=0:pi/5:pi;y=sin(x);
disp([x’ y’]);
0 0
0.6283 0.5878
1.2566 0.9511
1.8850 0.9511
2.5133 0.5878
3.1416 0.0000
Format command
Control the display mode , Until the next format Before it appeared , This article format The order has been in effect .
x=1.23456789;
format short;disp(pi);
3.1416
format long;disp(pi);
3.141592653589793
format short e;disp(pi);
3.1416e+000
format +;disp(pi);
format bank;disp(pi);
3.14
2、 function fprintf
fprintf(format);
fprintf(format,variables);
fprintf(fid,format,variables);
for example :
fprintf(‘i am concreten’);
i am concrete
a=3;b=‘s’;
fprintf(‘this is a %d and %s n’,a,b);
this is a 3 and s
边栏推荐
- 天书夜读笔记——反汇编引擎xde32
- Bi-sql Union
- What to learn in VB [easy to understand]
- 云开发技术峰会·公益编程挑战赛【火热报名中】!
- Default methods for Scala sample classes
- Basic knowledge of assembly language (2) -debug
- ImageView shows network pictures
- Add information on the left and add parts on the right of the status bar
- bindservice方法实现音乐播放暂停
- 利用 Redis 的 sorted set 做每周热评的功能
猜你喜欢
随机推荐
丹麥技術大學首創將量子計算應用於能源系統潮流建模
腾讯云WeCity解决方案
使用 Loki 微服务模式部署生产集群
Scala sample class
Bi-sql create
Scala adapter pattern
Bi-sql - different join
用手机在同花顺上开户靠谱吗?这样炒股有没有什么安全隐患
对技术的乐观,正让戴尔取得比想象中更多的成就
How about compass stock trading software? Is it safe?
Lenovo tongfuyao: 11 times the general trend, we attacked the city and pulled out the stronghold all the way
How to store dataframe data in pandas into MySQL
void* 指针
汇编语言(2)基础知识-debug
lnmp环境安装ffmpeg,并在Yii2中使用
4 years of working experience, and you can't tell the five communication modes between multithreads. Can you believe it?
汇编语言(3)16位汇编基础框架与加减循环
Novice, let me show you the "soft test" at one time
Using bindservice method to pause music playing
Bi SQL alias








