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 ...
随机推荐
- 根据条件决定是否为input设置只读属性
代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...
- Python3 ssl模块不可用的问题
编译安装完Python3之后,使用pip来安装python库,发现了如下报错: $ pip install numpy pip is configured with locations that re ...
- express + mongodb 搭建一个简易网站 (四)
express + mongodb 搭建一个简易网站 (四) 目前网站整体页面都已经能全部展示了,但是,整个网站还有两个块需要做完才能算完整,一个连接数据库,目前网站上的数据都是抓取的本地假数据,所以 ...
- 14.7.1&14.7.2
ArrayList <Object> list = new ArrayList<>(); //实例化ArrayList int i; int j; for(i = 1; i & ...
- scrollLeft滚动(用animate替代)
原: let checkedLeft1 = $('#dateBox').find('.checked').position().left let checkedLeft2 = $('#dateBox' ...
- Codeforces Beta Round #14 (Div. 2)
Codeforces Beta Round #14 (Div. 2) http://codeforces.com/contest/14 A 找最大最小的行列值即可 #include<bits/s ...
- 使用VisualSVN Server搭建SVN服务器[xyytit]
使用 VisualSVN Server来实现主要的 SVN功能则要比使用原始的 SVN和 Apache相配合来实现源代码的 SVN管理简单的多,上手也没有那么复杂. 下面就看看详细的说明 Visual ...
- PAT L2-005 集合相似度(模拟集合set)
给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你的任务就是计算任意一对给定集合的相似度. 输入格式: 输 ...
- 【转】Hadoop HDFS分布式环境搭建
原文地址 http://blog.sina.com.cn/s/blog_7060fb5a0101cson.html Hadoop HDFS分布式环境搭建 最近选择给大家介绍Hadoop HDFS系统 ...
- Spring框架中Bean管理的常用注解
1. @Component:组件.(作用在类上)可以作用在任何一个类上 2. Spring中提供@Component的三个衍生注解:(功能目前来讲是一致的) * @Controller -- 作用在W ...