Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Chi Square User Created File Date: Fri, 25 Mar 2011 20:00:21 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 25 Message-ID: <imis8l$o85$1@fred.mathworks.com> References: <img8ik$cba$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-01-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1301083221 24837 172.30.248.46 (25 Mar 2011 20:00:21 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Fri, 25 Mar 2011 20:00:21 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:718194 "Paul " <sweeprower@yahoo.com> wrote in message <img8ik$cba$1@fred.mathworks.com>... > All, > Would appreciate some help here: > Just trying to expand my MATLAB knowledge. I have a problem from a help book that I cant figure: > I have two vectors > x=[1 7 8 6 5 7 3 5 4] > e=[2 6 10 4 3 6 1 2 3] > the formula states that when an element of e <5 then you add it to the next element, if it is still less than 5 then you add it to the next number all numbers added together are removed from the modified vect, so > emodified would look like > emod=[8 10 7 6 6] > I understand its an for loop with if else statements but I cant get the vector to shorten essentially I get > e=[8 6 10 7 3 6 3 5 3] > the problem gives a hint that says test with cumsum but I am failing to see how that will help > Thanks > Paul - - - - - - - - - - - You shouldn't attempt to put your answers back into 'e'. Create a new vector and call it 'emod'. Make a for-loop which accumulates a sum from the 'e' elements. The for-loop index will serve to access the 'e' elements but you will have to maintain another independent index to access 'emod'. When your accumulated sum becomes greater than or equal to 5, you put that sum into 'emod', reset the accumulated sum to zero, advance the 'emod' index, and then continue. As for the 'cumsum' hint, ask yourself what can be said about the size of elements of cumsum(emod) if you have done as above. If you have reached the end of 'e' and the accumulated sum is still less than 5, should it be put into 'emod' or not? You will have to decide that based on your reading of the problem. You haven't explained what the 'x' vector has to do with the problem. Roger Stafford