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的更多相关文章

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

  2. Matlab编程基础

    平台:Win7 64 bit,Matlab R2014a(8.3) “Matlab”是“Matrix Laboratory” 的缩写,中文“矩阵实验室”,是强大的数学工具.本文侧重于Matlab的编程 ...

  3. [转] Loren on the Art of MATLAB

    http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/ Loren ...

  4. MATLAB cell 数组介绍

    转载:http://www.matlabsky.com/forum.php?mod=viewthread&tid=21089 由于工作需要,经常要处理大量的实验数据.基本都是由仪器导出来,随着 ...

  5. 在octave语言中K-means聚类算法求聚类中心的向量化计算

    使用octave编程的时候,一定要注意使用向量化编程的思想,下面我就说说我今天做题遇到的一个K-means聚类问题,如何使用octave中的函数向量计算聚类中心centroids. octave几个函 ...

  6. 【Matlab编程】Matlab高效编程技巧

    1.默认状态下,matlab显示精度是short型,而默认的计算精度是double型,并且显示精度与计算精度没有关系. 2. 一只失明的猫的问题:注意方法! 3.给数组预分配空间是基本的高效编程准则之 ...

  7. function [eigf,eigv,dof]=laplaceeig(node,elem,problem)

    function [eigf,eigv,dof]=laplaceeig(node,elem,problem) % -boundary eigenvalue problem % problem='0-b ...

  8. 社区发现的3个评估指标:标准化互信息NMI,ARI指标,以及模块度(modularity)

    转载请注明出处:http://www.cnblogs.com/bethansy/p/6890972.html 一.已知真实社区划分结果 1.NMI指数,互信息和标准化互信息 具体公式和matlab代码 ...

  9. matlab实用教程

    苏金明.2005.电子工业     1 语句末尾加 : 可以不显示到屏. who 查看变量 whos 列出变量信息 exist t 判断变量是否在空间中. help 函数 doc 函数 : doc f ...

随机推荐

  1. fm 讲解加代码

    转自: 博客 http://blog.csdn.net/google19890102/article/details/45532745/ github https://github.com/zhaoz ...

  2. java多线程实例(2)

    public class ThreadDemo05 { public static void main(String args[]) { // 四个售票点应该控制同一个资源 Demo d = new ...

  3. JavaScript实现AOP(面向切面编程,装饰者模式)

    什么是AOP? AOP(面向切面编程)的主要作用是把一些跟核心业务逻辑模块无关的功能抽离出来,这些跟业务逻辑无关的功能通常包括日志统计.安全控制.异常处理等.把这些功能抽离出来之后, 再通过“动态织入 ...

  4. C++强制转换

    static_cast,dynamic_cast, const_cast, reinterpret_cast dynamic_cast比static_cast多了安全检测,判断源和目标有无继承被继承关 ...

  5. [leetcode]346. Moving Average from Data Stream滑动窗口平均值

    Given a stream of integers and a window size, calculate the moving average of all integers in the sl ...

  6. springmvc在处理请求过程中出现异常信息交由异常处理器进行处理,自定义异常处理器可以实现一个系统的异常处理逻辑。为了区别不同的异常通常根据异常类型自定义异常类,这里我们创建一个自定义系统异常,如果controller、service、dao抛出此类异常说明是系统预期处理的异常信息。

    springmvc在处理请求过程中出现异常信息交由异常处理器进行处理,自定义异常处理器可以实现一个系统的异常处理逻辑. 1.1 异常处理思路 系统中异常包括两类:预期异常和运行时异常RuntimeEx ...

  7. Struts2的拦截器技术

    1. 拦截器的概述 * 拦截器就是AOP(Aspect-Oriented Programming,面向切面)的一种实现.(AOP是指用于在某个方法或字段被访问之前,进行拦截然后在之前或之后加入某些操作 ...

  8. EF6.0新特性-DbCommandInterceptor实现非SQL端读写分离

    前几天看了一个基于sqlserver的负载均衡与读写分离的软件Moebius,实现的方式还是不错的,这使得用sqlserver数据库的同学时有机会对数据库进行更有效的优化了

  9. Algorithmic Trading[z]

    Algorithmic Trading has been a hot topic for equity/derivative trading over a decade. Many ibanks an ...

  10. Tomcat设置默认时区

    本文讲解如何在tomcat启动时设置JVM默认时区. 环境:JDK1.8.114 web容器:Tomcat 9 tomcat启动脚本 /etc/init.d/tomcat 操作系统ubuntu 16 ...