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 ...
随机推荐
- Python中文件编码的检测
前言: 文件打开的原则是“ 以什么编码格式保存的,就以什么编码格式打开 ”,我们常见的文件一般是以“ utf-8 ”或“ GBK ”编码进行保存的,由于编辑器一般设置了默认的保存和打开方式,所以我们在 ...
- Ansible Playbook Conditionals
通常,play的结果可能取决于变量的值,facts(有关远程系统的知识)或先前的任务结果. 在某些情况下,变量的值可能取决于其他变量. 此外,可以创建其他组,以根据主机是否与其他条件匹配来管理主机. ...
- Ubuntu下Eclipse热键Ctrl+Alt+Up无效的解决
原文链接 :http://rox.iteye.com/blog/875078 现在好多链接都打不开了, Ubuntu下一直用NetBeans开发,改了热键为Eclipse的,复制行不管用,一直认为是N ...
- 配置python学习环境遇到的问题:[Decode error - output not utf-8]
因为前阵子学习monkeyrunner的时候,碰到了很多关于.py的脚本,其实我是一知半解的,也没打算去学习一下.将就着看看吧,后来无意中看到自动化测试工程师都要求会脚本语言的时候,刺激了我,想了想, ...
- Tomb Raider(暴力模拟)
Tomb Raider https://hihocoder.com/problemset/problem/1829?sid=1394836 时间限制:1000ms 单点时限:1000ms 内存限制:2 ...
- python的select服务端的代码和客户端的代码
服务端的代码 import socket import queue import select ip_bind = ("127.0.0.1",9000) message_queue ...
- tortoise svn 请求的名称有效,但是找不到请求的类型的数据
可能是博客园出bug了,现在无法放图,间断重复刷新十多次依然如故,弃之 这个问题是在安装完svn服务器(visual svn)后复制url,tortoise svn import 粘贴url后 出现的 ...
- 使用maven管理引入jdk1.8
需要在配置文件settings.xml中加入: <profile> <id>jdk-1.8</id> <activation> <activeBy ...
- AssemblyVersion,AssemblyFileVersion解释以及获取
简而言之,AssemblyVersion: 是程序集的版本,.NET的CLR用,用于标识出该dll的版本信息,用于定义强名称的版本号: AssemblyFileVersion: 为编译器生成的文件加入 ...
- css3阴影效果
http://blog.csdn.net/freshlover/article/details/7610269