# Matlab Help!! vector/if statement and for loop

Discussion in 'Programmer's Corner' started by Judas543, Feb 20, 2010.

1. ### Judas543 Thread Starter Member

Jan 26, 2010
60
0
Don't really know where to begin but here's what information they give and what i have so far. I guess what my question is, is what am i suppose to do and how am i suppose to do it. It says i need to use iteration, so that means "for x=" then if->else if>else if->else-> end" format right? SO could someone help me start it

Separating a vector into 6 subsets:

%Use the following vector given for Matlab:
D = [ 23, -5, 4, 0, -10, 45, 3, -3, 34, -9, 1, 25, 87, 21, -7, 4, -2, 6, 62, -22, -6, -17]

posEven = [4,34,4,6,62]

negEven = [-10,-2,-22,-6]

posodd = [23,45,25,87,21]

negodd = [-5,-3,-9,-7,-17]

posNeg = [1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0]

big = [45, 34, 87, 62]

Example given to us:

If D = [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 34, 87],
posEven=[2,4,34]
negEven=[-4,-2]
posOdd=[l,3,5,87]
negodd=[-3,-1]
posNeg = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1] and
big = [34, 87]

Use the following vector (copy and paste in Matlab):

D = [ 23, -5, 4, 0, -10, 45, 3, -3, 34, -9, 1, 25, 87, 21, -7, 4, -2, 6, 62, -22, -6, -17]

2. ### msr Well-Known Member

Jul 8, 2008
62
1
As far as I could understand, what you need to do is:

For each value on vector D you have to know in which subset it will have to be, adding this value to that subset.
With If statements you test all six conditions you have.