MATLAB Answers

Simpl equestion about CUMSUM

4 views (last 30 days)
Mohsen
Mohsen on 14 Jun 2013
How can I rewrite the following code using cumsum?
for i=0:299
A(i+1)=sum(B > i);
end
Many thanks!
  2 Comments
Mohsen
Mohsen on 14 Jun 2013
Size of A is (300,1) and Size of B is (1,65535)

Sign in to comment.

Accepted Answer

Kye Taylor
Kye Taylor on 14 Jun 2013
Edited: Kye Taylor on 14 Jun 2013
I don't think I would use cumsum here. Instead, try
A = sum(bsxfun(@gt,B',0:299));
Note, this command above assumes B is a row vector (the 1-by-35535 vector you mention).

More Answers (1)

Mohsen
Mohsen on 14 Jun 2013
Thanks a lot Kye Taylor !

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!