Simpl equestion about CUMSUM

How can I rewrite the following code using cumsum?
for i=0:299
A(i+1)=sum(B > i);
end
Many thanks!

2 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 14 de Jun. de 2013
What is the size of B?
Mohsen
Mohsen el 14 de Jun. de 2013
Size of A is (300,1) and Size of B is (1,65535)

Iniciar sesión para comentar.

 Respuesta aceptada

Kye Taylor
Kye Taylor el 14 de Jun. de 2013
Editada: Kye Taylor el 14 de Jun. de 2013

0 votos

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).

Más respuestas (1)

Mohsen
Mohsen el 14 de Jun. de 2013

0 votos

Thanks a lot Kye Taylor !

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 14 de Jun. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by