From: "Xuefei Cao" <>
Newsgroups: comp.soft-sys.matlab
Subject: How to sum to a threshold?
Date: Fri, 29 Apr 2011 01:09:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 6
Message-ID: <ipd33g$5a$>
Reply-To: "Xuefei Cao" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1304039345 170 (29 Apr 2011 01:09:05 GMT)
NNTP-Posting-Date: Fri, 29 Apr 2011 01:09:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2450674
Xref: comp.soft-sys.matlab:724370

Hi everyone,

I'm trying to sum the elements of a vector, and the sum should stop when the accumulated sum accounts for, say 90% of the overall sum. For example: if V=[ 4 3 2 1], the program should stop when it takes 3 because (4+3+2)/sum(V)=90%.

Is there any elegant method other than using while loop?