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

Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 14일
What is the size of B?
Mohsen
Mohsen 2013년 6월 14일
Size of A is (300,1) and Size of B is (1,65535)

댓글을 달려면 로그인하십시오.

 채택된 답변

Kye Taylor
Kye Taylor 2013년 6월 14일
편집: Kye Taylor 2013년 6월 14일

0 개 추천

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

추가 답변 (1개)

Mohsen
Mohsen 2013년 6월 14일

0 개 추천

Thanks a lot Kye Taylor !

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2013년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by