Simpl equestion about CUMSUM

1 visualizzazione (ultimi 30 giorni)
Mohsen
Mohsen il 14 Giu 2013
How can I rewrite the following code using cumsum?
for i=0:299
A(i+1)=sum(B > i);
end
Many thanks!
  2 Commenti
Azzi Abdelmalek
Azzi Abdelmalek il 14 Giu 2013
What is the size of B?
Mohsen
Mohsen il 14 Giu 2013
Size of A is (300,1) and Size of B is (1,65535)

Accedi per commentare.

Risposta accettata

Kye Taylor
Kye Taylor il 14 Giu 2013
Modificato: Kye Taylor il 14 Giu 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).

Più risposte (1)

Mohsen
Mohsen il 14 Giu 2013
Thanks a lot Kye Taylor !

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by