mod

Remainder after division (modulo operation)

除法(模运算)之后的余数

Syntax

b = mod(a,m)

Description

b = mod(a,m) returns the remainder after division of a by m, where a is the dividend and m is the divisor. This function is often called the modulo operation, which can be expressed as b = a - m.*floor(a./m). The mod function follows the convention that mod(a,0) returns a.

b = mod(a,m)返回a除以m后的余数,其中a是被除数,m是除数。此函数通常称为模运算,可表示为 b = a - m.*floor(a./m)。 mod函数遵循mod(a,0)返回a的约定。


Remainder After Division of Scalar

% Remainder After Division of Scalar
% Compute 23 modulo 5. b = mod(23,5)

b = 3;


Remainder After Division of Vector

Find the remainder after division for a vector of integers and the divisor 3.

a = 1:5;
m = 3;
b = mod(a,m)
b = 1×51     2     0     1     2

Remainder After Division for Positive and Negative Values

Find the remainder after division for a set of integers including both positive and negative values. Note that nonzero results are always positive if the divisor is positive.

在除法之后找到一组整数,包括正值和负值。 请注意,如果除数为正,则非零结果始终为正。

a = [-4 -1 7 9];
m = 3;
b = mod(a,m)
b = 1×42     2     1     0

注:这里说明下负数如何对一个正数取模,或者做mod运算,例如求:

mod(-4,3),算法流程是这样的,先根据3对负数进行处理,即-4+3+3=2,这样就处理成了正数,然后在取余运算,mod(2,3)=2。

同理,mod(-1,3),先将-1+3 = 2,之后mod(2,3)=2.

至于为什么要加3,我们不妨认为对谁取余,例如mod(a,m),a /m = n ...b,也就是a除以m得到n余b,那么a = m * n + b,我们需要求得是b,从这个式子中我们可以看出,a加上几个m之后再除以m,是不影响b的值的,所以这种处理是可以的。


Remainder After Division for Negative Divisor

Find the remainder after division by a negative divisor for a set of integers including both positive and negative values. Note that nonzero results are always negative if the divisor is negative.

在除法之后找到一个负除数,得到一组整数,包括正值和负值。 请注意,如果除数为负,则非零结果始终为负。

a = [-4 -1 7 9];
m = -3;
b = mod(a,m)
b = 1×4-1    -1    -2     0注:花里胡哨的,处理的方法和被除数a是负数时原理一样,这时,如果a是正数,则对a加几个m之后变成负数,在对m取余。

Remainder After Division for Floating-Point Values

Find the remainder after division for several angles using a modulus of 2*pi. Note that mod attempts to compensate for floating-point round-off effects to produce exact integer results when possible.

使用2 * pi的模数找到除法后的几个角度的余数。 请注意,mod会尝试补偿浮点舍入效果,以便在可能的情况下生成精确的整数结果。

theta = [0.0 3.5 5.9 6.2 9.0 4*pi];
m = 2*pi;
b = mod(theta,m)
b = 1×60    3.5000    5.9000    6.2000    2.7168         0

注:除数是浮点数而已,按照MATLAB能处理的精度算就是了,让它算。



Differences Between mod and rem

The concept of remainder after division is not uniquely defined, and the two functions mod and rem each compute a different variation. The mod function produces a result that is either zero or has the same sign as the divisor. The rem function produces a result that is either zero or has the same sign as the dividend.

除法后的余数的概念不是唯一定义的,并且两个函数mod和rem各自计算不同的变化。 mod函数产生的结果为零或与除数具有相同的符号。 rem函数产生的结果为零或与被除数具有相同的符号。

Another difference is the convention when the divisor is zero. The mod function follows the convention that mod(a,0) returns a, whereas the rem function follows the convention that rem(a,0)returns NaN.

另一个区别是除数为零时的约定。 mod函数遵循mod(a,0)返回a的约定,而rem函数遵循rem(a,0)返回NaN的约定。

Both variants have their uses. For example, in signal processing, the mod function is useful in the context of periodic signals because its output is periodic (with period equal to the divisor).

两种变体都有其用途。 例如,在信号处理中,mod函数在周期信号的上下文中是有用的,因为它的输出是周期性的(周期等于除数)。

Congruence Relationships

同余关系

The mod function is useful for congruence relationships: a and b are congruent (mod m) if and only if mod(a,m) == mod(b,m). For example, 23 and 13 are congruent (mod 5).

mod函数对于同余关系很有用:当且仅当mod(a,m)== mod(b,m)时,a和b是全等的(mod m)。 例如,23和13是一致的(模5)。

【 MATLAB 】mod 函数介绍相关推荐

  1. Matlab mod函数 对应C语言 函数

    Matlab mod函数 对应C语言 函数 2010-09-10 23:43 Matlab中的mod函数,不同于C语言中的"%",在C中没有专门对应的函数. Matlab的mod函 ...

  2. MATLAB mod函数的一些坑和总结

    mod函数:模运算(求余数) x = mod(m, n) % 返回 m 除于 n 后的余数 >> mod(23, 5) %标量进行模运算 ans =3 >> a = [3 5 ...

  3. matlab histeq cy源代码,matlab histeq函数介绍(示例代码)

    Histeq Enhance contrast using histogram equalization 该函数通过直方图均衡化来添加对照度 Syntax J = histeq(I,hgram) De ...

  4. matlab histequ,matlab histeq函数介绍

    Histeq Enhance contrast using histogram equalization 该函数通过直方图均衡化来增加对比度 Syntax J = histeq(I,hgram) De ...

  5. 【 MATLAB 】rem 函数介绍

    rem函数和mod函数很相似,二者认真看一个,另一个看一下区别即可. mod函数介绍:[ MATLAB ]mod 函数介绍 rem Remainder after division Syntax r ...

  6. matlab histequ,matlab histeq函数引见

    matlab histeq函数介绍 Histeq Enhance contrast using histogram equalization 该函数通过直方图均衡化来增加对比度 Syntax J =  ...

  7. 【 MATLAB 】filter 函数介绍 之 Filter Data in Sections

    [ MATLAB ]filter 函数介绍(一维数字滤波器) 在上篇博文中,里面有一个例子,就是过滤部分中的数据,这个部分中的数据的意思是如果有一个向量需要过滤,我们可以把它分为几段,然后分段过滤. ...

  8. MATLAB求函数极限的简单介绍

    系列优质文章索引 centos7配置静态网络常见问题归纳_张小鱼༒的博客-CSDN博客matlab系统环境思维导图_张小鱼༒的博客-CSDN博客 计算机组成原理--中央处理器cpu_cpu内通用寄存器 ...

  9. MATLAB中的mvnrnd函数介绍

    mvnrnd函数介绍 mvnrnd函数可以用于生成不同类别模式的数据,数据要服从正态分布(高斯分布). 使用matlab来实现的代码如下: matlab实现代码如下: mul = [1 2]; SIG ...

  10. matlab的mod函数,mod函数(mod函数的使用方法)

    取模,即求两数相除的余数=MOD(7,3)7/3的余数 就是求出两个数相除的余数.如:mod(4,5)=4,即mod(A ,B)中A伟被除数,B为除数,求出二者的余数即为函数的返回值. mod(10, ...

最新文章

  1. JVM堆 栈 方法区详解
  2. 实战 Prometheus 搭建监控系统
  3. 欧盟最新《AI网络安全政策发展框架》
  4. VMware HA环境搭建七:WIN2012 ISCSI目标服务器的安装
  5. vue内引入jsPlumb流程控制器(一)
  6. python对excel某一列去重-python中怎么对dataframe列去重
  7. 32.210内存的知识
  8. 基于语义嵌入模型与交易信息的智能合约自动分类系统
  9. mysql 清洗字段数据,根据字段条件清理MySQL数据库数据
  10. python基础-元组
  11. Spring→面向切面编程AOP、相关概念、通知Advice类型、配置切面切入点通知、AOP相关API、AOP代理类ProxyFactoryBean、AOP注解@AspectJ
  12. html中input描述,input的type值类型和描述-HTML
  13. c语言程序功能实现不了,请高手帮忙看看我的程序,编译不报错,但是实现不了功能...
  14. 系统详细设计过程指南
  15. Word转换成pdf之pdf虚拟打印机如何使用操作教程
  16. w10连接远程计算机控制,win10远程电脑怎么设置_win10通过远程桌面控制其他电脑的方法...
  17. 王廷强老师--研发质量管理--GDT几何形位公差高级专家--沪师经纪刘建
  18. 详解torch.view()的-1参数是什么意思
  19. 画小米的新Logo只用border-radius可不行!
  20. 数据链路层的子层MAC层(图文详解)

热门文章

  1. python编程从入门到实践——16章
  2. 苹果手机有没有计算机记录,苹果手机中的safari浏览记录怎么恢复?苹果恢复大师教你...
  3. C盘清理(主要的大文件清理)
  4. 扩展坞可以把手机投到显示器吗_华为P20投屏助手,绿联USB-C扩展坞使用说明
  5. JavaSE方法(构造方法)与方法重载基础练习题
  6. 清明时节雨纷纷,心思却剪不断,理还乱
  7. r语言实现岭回归_R语言回归篇
  8. usrp n310测试总结---环境搭建篇2-uhd-dpdk干货
  9. windows主机和ubuntu互传文件的4种方法
  10. JAVA之基数排序LSD顺序