Matlab bsxfun函数解析
bsxfun是一个matlab自版本R2007a来就提供的一个函数,作用是”applies an element-by-element binary operation to arrays a and b, with singleton expansion enabled。
bsxfun的执行效果是这样的,以两个变量a+b为例,如果a和b的各维度大小相同,那么c=a+b. 但如果有某维大小不同,且a或b必须有一个在这一维度的大小为1, 那么bsxfun就将维度大小为一的这个虚拟的复制一些来使与多的维数大小一样。
举例:
>> a = randn(3,1), b = randn(1,3)a =0.53771.8339-2.2588b =0.8622 0.3188 -1.3077>> bsxfun(@plus,a,b)ans =1.3998 0.8564 -0.77002.6961 2.1527 0.5262-1.3967 -1.9401 -3.5665>> a = randn(4,3), b = randn(1,3)a =-0.4336 -1.3499 0.71470.3426 3.0349 -0.20503.5784 0.7254 -0.12412.7694 -0.0631 1.4897b =1.4090 1.4172 0.6715>> bsxfun(@plus,a,b)ans =0.9754 0.0673 1.38621.7517 4.4521 0.46654.9874 2.1426 0.54744.1785 1.3541 2.1612>> a = randn(4,3), b = randn(2,3)a =-1.2075 1.0347 -0.78730.7172 0.7269 0.88841.6302 -0.3034 -1.14710.4889 0.2939 -1.0689b =-0.8095 1.4384 -0.7549-2.9443 0.3252 1.3703>> bsxfun(@plus,a,b)
Error using <u>bsxfun</u>
Non-singleton dimensions of the two input arrays must match each other.>>
以上操作也可以通过repmat函数来进行事先,但是repmat函数会复制矩阵,增加了额外的内存和时间。bsxfun是虚拟的复制,实际上通过for来实现,但bsxfun不会有使用matlab的for所带来额外时间。
附:
C = bsxfun(fun,A,B) appliesthe element-by-element binary operation specified by the functionhandlefun to arrays A and B,with singleton expansion enabled.fun can be oneof the following built-in functions:
@plus Plus
@minus Minus
@times Array multiply
@rdivide Right array divide
@ldivide Left array divide
@power Array power
@max Binary maximum
@min Binary minimum
@rem Remainder after division
@mod Modulus after division
@atan2 Four quadrant inverse tangent
@hypot Square root of sum of squares
@eq Equal
@ne Not equal
@lt Less than
@le Less than or equal to
@gt Greater than
@ge Greater than or equal to
@and Element-wise logical AND
@or Element-wise logical OR
@xor Logical exclusive OR
参考:
http://www.cnblogs.com/hxsyl/p/4429316.html
http://blog.sina.com.cn/s/blog_9e67285801010ttn.html
Matlab bsxfun函数解析相关推荐
- matlab newff函数解析
matlab newff函数解析 newff Syntax Description Examples Algorithm 传递函数TFi 学习训练函数BTF 参数说明 see:http://matla ...
- Matlab bsxfun函数
bsxfun 两个数组间元素逐个计算. 语法: C=bsxfun(fun,A,B) 函数描述: 两个数组间元素逐个计算,fun是函数句柄或者m文件,也可以为如下内置函数 @plus ...
- MATLAB filter函数解析
现在正在学习MATLAB信号处理方面的应用,程序中遇到filter函数,从网上查阅资料,我能找到的资料感觉写的也是模棱两可,不易使人明白,所以就花了一下午的时间好好研究了下,终于知道这个函数的使用方法 ...
- matlab butter()函数解析
butter函数是求Butterworth数字滤波器的系数: [B,A]=butter(n,wn) n是滤波器的阶数,根据需要选择合适的整数,Wn是归一化截止频率,又叫自然频率,Wn = 截止频率*2 ...
- matlab atan2函数解析
旁边的图片显示内容是:在一个单位圆内atan2函数在各点的取值.圆内标注代表各点的取值的幅度表示. 图片中,从最左端开始,角度的大小随着逆时针方向逐渐从-π增大到+π,并且角度大小在点位于最右端时,取 ...
- matlab PHASECONG3函数解析
大佬网站的链接:PHASECONG3 这个函数是用来计算图像的边缘和角的相位一致性 下面是该函数的注释 This function calculates the PC_2 measure of pha ...
- matlab中dist的命令,matlab dist函数
dist--欧式距离加权函数(Euclidean distance weight function) 语法: Z = dist(W,P) df = dist('deriv') D = dist(pos ...
- Matlab中bsxfun和unique函数解析
一.问题来源 来自于一份LSH代码,记录下来. 二.函数解析 2.1 bsxfun bsxfun是一个matlab自版本R2007a来就提供的一个函数,作用是"applies an elem ...
- Matlab中用到的bsxfun函数
bsxfun函数 最近在读dollar toolbox代码,该工具包是用matlab和c混编的,对其中的很多matlab函数不是很熟悉,有的更是查了忘,再见到再查,所以就在这里,边学习边整理,方便以后 ...
最新文章
- 长文 | 从发展轨迹、社会变迁和人口数据变化来看工具类产品的发展出路有哪些(1)
- 月费10元起!中国移动推年轻人的第一张5G元素电话卡
- Springboot 整合 Netty 实战(附源码)
- tasklist 结束进程_Windows: windows下的终止进程的命令(tasklist/tskill)
- 1650显卡和1050T显卡差距大吗?
- python爬虫 书籍 外文_Python爬虫——WuXiaWorld英文版小说
- 关于group by 两个或以上条件的分析
- Android Multimedia框架总结(十八)Camera2框架从Java层到C++层类关系
- 浅谈Spring如何利用三个缓存Map解决循环依赖
- 20170306 小兵的觉悟就是好好吃饭
- 【Android自动化测试】Robot Framework+adb框架(四)——L2层关键字
- FormulaR1C1是EXCEL中单元格公式输入方法
- 《说服力-让你的PPT会说话》9月上海公开课简章
- QtScrcpy手机投屏电脑利器连接Android设备
- 自然语言处理2——语言学基础
- 服务器win2003的远程在哪里,走进win2003远程桌面的神奇世界
- Python Ajax爬取微博个人博客数据
- 极限反转-EA 年盈利翻4倍,月收益38%左右,策略稳定浮亏小
- java Eclipse 快捷键
- php用什么打开_我的php文件怎么打开_如何打开php文件的办法
热门文章
- Java 的历史和版本
- 软件型企业认定资质的好处
- GSL科学计算库——计算高斯-勒让德积分
- 例说BPEL4WS(5)---伙伴与伙伴连接
- poi处理word内容的公式_Java 使用 POI 操作 XWPFDocument 中的 XWPFParagraph(段落)对象的属性略解 Wor - 链滴...
- 区块链技术研究热点有哪些
- matplotlib和seaborn中的颜色图(colormap)和调色板(color palette)
- JAVA12_12学习总结(JavaScript)
- Pycharm 配置 Autopep8
- 使用rust和actix实现一个视频流服务器