Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

How to Add same Index Array Elements in Octave

I've generated elements w(i,j) of an array, most of which are zeros. Some of the elements have the same index j and I'd like to add them up and show each j with its corresponding summed up value. I tried v = sum(w) and it did show the summed up values but as elements of a large matrix, with most elements being zero. Is there a different way to accomplish that task?
0
judico
Asked:
judico
  • 2
1 Solution
 
judicoAuthor Commented:
This is one possible solution, although I was hoping that there might be a way to avoid looping:

for j = 1:arr_rows
if sum(w)'(j) != 0
[j, sum(w)'(j)]
endif
endfor
0
 
judicoAuthor Commented:
This is the best solution I could come up with so far. There are memory problems for large arrays. I may address these problems later.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now