accumarray
Example Create a -by- vector and sum values for repeated -D subscripts:
val = :;
subs = [; ; ; ; ]
subs = A = accumarray(subs, val)
A =
% A() = val() =
% A() = val()+val() = + =
% A() =
% A() = val()+val() = + = The order of the subscripts matters:
val = :;
subs=[ ; ; ; ; ; ];
B1 = accumarray(subs,val,[],@(x)sum(diff(x))) B1 = - - Example Create a -by--by- array and sum values for repeated -D subscripts:
val = :;
subs = [ ; ; ; ; ]; A = accumarray(subs, val)
A(:,:,) = A(:,:,) = Example Create a -by--by- array, and sum values natively:
val = :;
subs = [ ; ; ; ; ]; A = accumarray(subs, int8(val), [], @(x) sum(x,'native'))
A(:,:,) = A(:,:,) = class(A)
ans =
int8 Example Pass multiple subscript arguments in a cell array. Create a -element vector V:
V = :; Create three -element vectors, one for each dimension of the resulting array A. Note how the indices of these vectors determine which elements of V are accumulated in A:
% index index => V()+V() => A(,,)
% | |
rowsubs = [ ];
colsubs = [ ];
pagsubs = [ ];
% |
% index => V() => A(,,)
%
% A(,,) = V() + V() = + =
% A(,,) = V() = Call accumarray, passing the subscript vectors in a cell array:
A = accumarray({rowsubs colsubs pagsubs}, V)
A(:,:,) =
% A(,,) is A(:,:,) = % A(,,) is Example Create an array with the max function, and fill all empty elements of that array with NaN:
val = :;
subs = [ ; ; ; ; ]; A = accumarray(subs, val, [ ], @max, NaN)
A =
NaN NaN NaN
NaN NaN Example Create a sparse matrix using the prod function:
val = :;
subs = [ ; ; ; ; ]; A = accumarray(subs, val, [ ], @prod, , true)
A =
(,)
(,)
(,) Example Count the number of entries accumulated in each bin:
val = ;
subs = [ ; ; ; ; ]; A = accumarray(subs, val, [ ])
A = Example Create a logical array that shows which bins will accumulate two or more values:
val = :;
subs = [ ; ; ; ; ]; A = accumarray(subs, val, [ ], @(x) length(x) > )
A = Example Group values in a cell array:
val = :;
subs = [ ; ; ; ; ]; A = accumarray(subs, val, [ ], @(x) {x})
A =
[ ] [] [] []
[2x1 double] [] [2x1 double] [] A{}
ans =
Examples
accumarray的更多相关文章
- MATLAB accumarray
先看看subs和val的具体内容 subs = [1 1 1; 2 1 2; 2 3 2; 2 1 2; 2 3 2]; subs = 1 1 1 2 1 2 2 ...
- Matlab编程基础
平台:Win7 64 bit,Matlab R2014a(8.3) “Matlab”是“Matrix Laboratory” 的缩写,中文“矩阵实验室”,是强大的数学工具.本文侧重于Matlab的编程 ...
- [转] Loren on the Art of MATLAB
http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/ Loren ...
- MATLAB cell 数组介绍
转载:http://www.matlabsky.com/forum.php?mod=viewthread&tid=21089 由于工作需要,经常要处理大量的实验数据.基本都是由仪器导出来,随着 ...
- 在octave语言中K-means聚类算法求聚类中心的向量化计算
使用octave编程的时候,一定要注意使用向量化编程的思想,下面我就说说我今天做题遇到的一个K-means聚类问题,如何使用octave中的函数向量计算聚类中心centroids. octave几个函 ...
- 【Matlab编程】Matlab高效编程技巧
1.默认状态下,matlab显示精度是short型,而默认的计算精度是double型,并且显示精度与计算精度没有关系. 2. 一只失明的猫的问题:注意方法! 3.给数组预分配空间是基本的高效编程准则之 ...
- function [eigf,eigv,dof]=laplaceeig(node,elem,problem)
function [eigf,eigv,dof]=laplaceeig(node,elem,problem) % -boundary eigenvalue problem % problem='0-b ...
- 社区发现的3个评估指标:标准化互信息NMI,ARI指标,以及模块度(modularity)
转载请注明出处:http://www.cnblogs.com/bethansy/p/6890972.html 一.已知真实社区划分结果 1.NMI指数,互信息和标准化互信息 具体公式和matlab代码 ...
- matlab实用教程
苏金明.2005.电子工业 1 语句末尾加 : 可以不显示到屏. who 查看变量 whos 列出变量信息 exist t 判断变量是否在空间中. help 函数 doc 函数 : doc f ...
随机推荐
- mysql 新增数据
- Error: Cannot find a valid baseurl for repo: epel
修改一下/etc/yum.repos.d/epel.repo文件, enable=1改为enable=0
- 结对项目3-bug的三种状态
这周和小伙伴结对构造程序,来深刻理解软件测试中,bug发现的三种状态. 1:不能触发Fault 2:触发Fault,但是不能触发Error 3:触发Error,但是不能产生Failure 我们完成的代 ...
- tf.equal()
equal( x, y, name=None ) 对输入的 x 和 y 两个 Tensor 逐元素(element-wise)做 (x == y) 逻辑比较,返回 bool 类型的 Tensor. 参 ...
- python之面向对象之反射运用
先看下hasattr和getattr在反射中的用法 import sys class apache(object): def __init__(self,tcp): self.tcp = tcp de ...
- 文件Move操作
#coding=utf-8 import os import shutil stra = "G:/should/v3/a" strb = "G:/should/v3/b& ...
- 源代码安装grub-customizer
wget https://launchpad.net/grub-customizer/5.0/5.0.6/+download/grub-customizer_5.0.6.tar.gztar zxvf ...
- [Selenium]Eclipse hangs at 57% in debug mode with TestNG tests
案例1: I am very thankful to saish and cbeust for the solution. I went through the similar issue with ...
- Socket使用大全
第一部分.概念的理解 1.什么是Socket? Socket又称之为“套接字”,是系统提供的用于网络通信的方法.它的实质并不是一种协议,没有规定计算机应当怎么样传递消息,只是给程序员提供了一个发送消息 ...
- 2018.09.16 codeforces1041C. Coffee Break(双端队列)
传送门 真心sb题啊. 考场上最开始看成了一道写过的原题... 仔细想了一会发现看错了. 其实就是一个sb队列. 每次插入到队首去就行了. 代码: #include<bits/stdc++.h& ...