Prev: Little error:
Next: Regarding bursts Detection in data
From: Samuel Mathew on 6 May 2010 09:59 Assuming I have a matrix such as Index Val1 Val2 Val3 a = [1 2 5 4 1 0 2 6 1 2 1 2 2 5 4 7 2 12 0 1 3 4 7 5 3 1 0 1 3 1 1 2] I need to add the column values within the matrix depending on the index value (i.e. all rows with index value 1 get added together, all with 2 ... etc.) in order to get a matrix a = [1 4 8 12 2 17 4 8 3 6 8 8] Thanks sam P.S - if it can be automated it would be a lot better - as my matrix row size is in the 100s
From: Steven Lord on 6 May 2010 10:12 "Samuel Mathew" <msam313(a)hotmail.com> wrote in message news:hruhva$dhc$1(a)fred.mathworks.com... > Assuming I have a matrix such as > Index Val1 Val2 Val3 > a = [1 2 5 4 1 0 2 6 > 1 2 1 2 2 5 4 7 > 2 12 0 1 > 3 4 7 5 > 3 1 0 1 > 3 1 1 2] > > I need to add the column values within the matrix depending on the index > value (i.e. all rows with index value 1 get added together, all with 2 ... > etc.) > > in order to get a matrix > > a = [1 4 8 12 > 2 17 4 8 > 3 6 8 8] Use ACCUMARRAY. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Matt J on 6 May 2010 10:15 help accumarray
From: Samuel Mathew on 6 May 2010 10:25 Thank you steven, but I can't seem to understand the help files on ACCUMARRAY - how does it work?? thanks "Steven Lord" <slord(a)mathworks.com> wrote in message <hruio3$610$1(a)fred.mathworks.com>... > > "Samuel Mathew" <msam313(a)hotmail.com> wrote in message > news:hruhva$dhc$1(a)fred.mathworks.com... > > Assuming I have a matrix such as > > Index Val1 Val2 Val3 > > a = [1 2 5 4 1 0 2 6 > > 1 2 1 2 2 5 4 7 > > 2 12 0 1 > > 3 4 7 5 > > 3 1 0 1 > > 3 1 1 2] > > > > I need to add the column values within the matrix depending on the index > > value (i.e. all rows with index value 1 get added together, all with 2 ... > > etc.) > > > > in order to get a matrix > > > > a = [1 4 8 12 > > 2 17 4 8 > > 3 6 8 8] > > Use ACCUMARRAY. > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ >
|
Pages: 1 Prev: Little error: Next: Regarding bursts Detection in data |