How to apply the following conditions
1 view (last 30 days)
Show older comments
sergio lores
on 14 Dec 2015
Commented: sergio lores
on 14 Dec 2015
hello, I have the following set of data in an array where I need to add the numbers on column 1 until the number on column 2 changes for example: column 2 has -1 for the first 28 figures so I add the numbers on column 1 and get 23 then add the numbers with a 1 then -1 and so on to get a list of the sums on every sign change.
-0.000220000000000109 -1
-0.000129999999999963 -1
0.000150000000000095 -1
-0.000310000000000032 -1
0.00305 -1
-0.000920000000000032 -1
0.00208000000000008 -1
-0.000480000000000036 -1
-8.99999999999235e-05 -1
0.000219999999999887 -1
0.000439999999999996 -1
0.000790000000000068 -1
-0.000350000000000072 -1
-0.000639999999999974 -1
-0.00143000000000004 -1
0.00127999999999995 -1
2.99999999999745e-05 -1
-0.000789999999999846 -1
0.00102999999999986 -1
-0.000399999999999956 -1
0.000870000000000148 -1
-0.000390000000000112 -1
-0.000219999999999887 -1
-0.000260000000000149 -1
-0.00109999999999988 -1
9.9999999999989e-05 -1
-0.00111000000000017 1
0 1
0.000289999999999901 1
-0.000760000000000094 1
0.000430000000000152 1
-0.000770000000000159 1
-0.000139999999999807 1
0.000549999999999828 1
0.000400000000000178 1
-0.000420000000000087 1
0.000350000000000072 1
0.00042999999999993 1
0.00055000000000005 1
0.000580000000000025 1
-0.000609999999999999 1
-0.00012000000000012 -1
-0.000319999999999876 -1
0.000489999999999879 -1
-0.000350000000000072 -1
0.000240000000000018 1
0.000230000000000175 1
0.00132999999999983 1
0 Comments
Accepted Answer
Walter Roberson
on 14 Dec 2015
v = yourArray(:,2);
idx = cumsum([true;v(1:end-1)~= v(2:end)]);
totals = accumarray(idx, yourArray(:,1));
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!