rem函数和mod函数很相似,二者认真看一个,另一个看一下区别即可。

mod函数介绍:【 MATLAB 】mod 函数介绍



rem

Remainder after division

Syntax

r = rem(a,b)

Description

r = rem(a,b) returns the remainder after division of a by b, where a is the dividend and b is the divisor. This function is often called the remainder operation, which can be expressed asr = a - b.*fix(a./b). The rem function follows the convention that rem(a,0) is NaN.

a/b之后的余数便是r。如果除数为0,则rem(a,0)为NaN,这和我们的认知也很符合。


Remainder After Division of Scalar

Compute the remainder after dividing 5 into 23.

a = 23;
b = 5;
r = rem(a,b)
r = 3

Remainder After Division of Vector

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

a = 1:5;
b = 3;
r = rem(a,b)
r = 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 have the same sign as the dividend.

a = [-4 -1 7 9];
b = 3;
r = rem(a,b)
r = 1×4-1    -1     1     0

注:从这个例子开始,就和mod函数不一样了,这里余数符号与被除数一致。

a = [-4 -1 7 9];
b = 3;
r1 = rem(a,b)
r2 = mod(a,b)

r1 =

-1    -1     1     0

r2 =

2     2     1     0

二者结果是不一样的,我们想想这个rem是怎么计算的。

它是先将被输出a中的符号去掉,当成正数来算,结果符号在和a一致即可。


Remainder After Division for Floating-Point Values

Find the remainder after division for several angles using a divisor of 2*pi. When possible, rem attempts to produce exact integer results by compensating for floating-point round-off effects.

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

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.

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.

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).

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

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

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

  2. matlab histequ,matlab histeq函数介绍

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

  3. matlab histequ,matlab histeq函数引见

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

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

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

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

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

  6. MATLAB中的mvnrnd函数介绍

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

  7. 基于Matlab的Robotics Toolbox工具箱的机器人仿真函数介绍(运动学)

    前言 随着我们了解到机器人如何建立运动学模型和动力学模型之后,我们可以使用Matlab中的仿真工具箱内来对模型的准确性进行验证,并且可以通过内置的函数进行简单的轨迹规划和可视化观察,本节涉及到的工具箱 ...

  8. Matlab中rem函数使用

    目录 语法 说明 示例 标量被除后的余数 向量被除后的余数 正值和负值被除后的余数 浮点值被除后的余数 rem函数是两个数相除之后的余数. 语法 a - 被除数 被除数,指定为标量.向量.矩阵或多维数 ...

  9. 判断闰年的Matlab/Python函数

    目录 写在前面 什么是闰年 判断闰年的Matlab函数 判断闰年的Python函数 参考 写在前面 在处理自然科学数据时,经常需要判断一个年份(这里说的年份都是公历)是否为闰年,本文首先简单介绍闰年的 ...

最新文章

  1. 垃圾回收器机制(二):快速解读GC算法之标记-清除,复制及标记整理-算法
  2. 本周不容错过的的9篇NLP论文 | PaperDaily #21
  3. windows下安装及配置 golang 的Web框架Beego环境
  4. static和瞬态_具有瞬态属性的视图对象的钝化和激活
  5. AIgorand的基本原理
  6. 一步一步配置DataGuard Broker
  7. php 手机端播放器,用JS代码适配电脑端和手机端播放器代码
  8. 如何在MVC中下载模板和上传word文件
  9. 1438.最小公倍数
  10. IOS 文件管理 2
  11. ESB和注册服务管理的区别
  12. 42. 确保lessT与operator小于具有相同的语义
  13. SQL 删除重复数据,只保留一行
  14. Scratch3.0——作品截图
  15. 机房温度不够冷?可能是系统有问题!
  16. ES7和ES8常见新特性
  17. 书评:程序员生涯--残缺世界的游击战术
  18. 从无栈协程到 C++异步框架
  19. 汉服经济迎来“井喷式”发展!vr全景助力汉服数字化蜕变
  20. 带宽-服务器测速(Speedtest)

热门文章

  1. 一起谈.NET技术,ASP.NET MVC Membership 权限 漫谈
  2. python虚拟环境安装pyqt5_python虚拟环境安装pyqt5
  3. 锐界机器人_看着就很酸爽,2.7T V6双涡轮,车则试驾新福特锐界ST
  4. onkeyup,onkeydown和onkeypress的区别介绍
  5. linux命令在哪里使用,在Linux不同场景中Linux命令的使用方法
  6. 微型计算机实验代码,上师大,微型计算机实验全代码.doc
  7. numpy 中的三个特别的索引操作 c_, r_, s_
  8. 测试另外一个厂商的T254 高频功率MOS管
  9. 面向世界、勇于进取、树立自信、保持特色--自博162
  10. 两款扁平步进电机及其驱动器VSMD102