Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Chi Square User Created File

Subject: Chi Square User Created File

From: Paul

Date: 24 Mar, 2011 20:12:04

Message: 1 of 2

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

Subject: Chi Square User Created File

From: Roger Stafford

Date: 25 Mar, 2011 20:00:21

Message: 2 of 2

"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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us