当前位置:网站首页>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
边栏推荐
- 1. 封装自己的脚手架 2.创建代码模块
- Library management system code source code (php+css+js+mysql) complete code source code
- 改造一下 BeanUtils,优雅的实现 List 数据拷贝
- Scala object blending trait
- Cobalt strike installation tutorial
- 天书夜读笔记——内存分页机制
- Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source! (high performance + high customization)
- JVM指令
- Syntax highlighting of rich text
- 新一代可级联的以太网远程I/O数据采集模块
猜你喜欢

Add information on the left and add parts on the right of the status bar

汇编语言(3)16位汇编基础框架与加减循环

Bi SQL alias

Deep learning LSTM model for stock analysis and prediction

Preliminary understanding of qtoolbutton

Zuckerberg demonstrated four VR head display prototypes, and meta revealed the "family" of metauniverse

Using macro code to generate handwriting automatically in word or WPS

图书馆管理系统代码源码(php+css+js+mysql) 完整的代码源码

JVM指令

Scala IO reads by lexical units and numbers
随机推荐
Bi SQL alias
Cobalt Strike安装教程
Program.launch(xxx)打开文件
vb学习什么[通俗易懂]
启动服务11111
归并排序求逆序数
天书夜读笔记——内存分页机制
腾讯云WeCity解决方案
Bi-sql - join
JS Chapter 1 Summary
AutoCAD - two extension modes
梦想CAD云图与GIS结合演示
Bi-sql create
【无标题】
void* 指针
1. 封装自己的脚手架 2.创建代码模块
51 single chip microcomputer multi computer communication
Scala classes inherit multiple attributes
天书夜读笔记——反汇编引擎xde32
VB 学习笔记