Path: news.mathworks.com!not-for-mail
From: "Xuefei Cao" <sophie.c1325@hotmail.com>
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$1@fred.mathworks.com>
Reply-To: "Xuefei Cao" <sophie.c1325@hotmail.com>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1304039345 170 172.30.248.35 (29 Apr 2011 01:09:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 29 Apr 2011 01:09:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2450674
Xref: news.mathworks.com 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?