Don\'t really know where to begin but here\'s what information theygive and what
ID: 3616919 • Letter: D
Question
Don't really know where to begin but here's what information theygive and what i have so far. I guess what my question is, is whatam i suppose to do and how am i suppose to do it. It says i need touse iteration, so that means "for x=" then if->else if>elseif->else-> end" format right? SO could someone help me startitSeparating a vector into 6 subsets:
http://img23.imageshack.us/img23/2995/44567558.png
%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]
Explanation / Answer
He, I have created your program. 1) Determine if the number is positive or negative 2) determine if the number is odd or even For this, mod(number,2) is used. 3) Add the numbers to vectors If it is unclear, send a private message! D = [ 23, -5, 4, 0, -10, 45, 3, -3, 34, -9, 1, 25, 87, 21,-7, 4, -2, 6, 62, -22, -6, -17]; %%%%%%%%%%%%%%%%% Initialize Parameters%%%%%%%%%%%%% SumPosEven = 0; SumPosOdd = 0; PosEven = []; PosOdd = []; SumNegEven = 0; SumNegOdd = 0 ; NegEven = []; NegOdd = []; Big = []; SumBig = 0; PosNeg = []; SumPosNeg = 0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for i=1:length(D) % Negativenumbers if D(i) < 0 SumPosNeg = SumPosNeg +1; PosNeg(SumPosNeg)=0; % determine if a number is odd oreven % modlus(number,2)= 0 for evennumbers ifmod(D(i),2)== 0 SumNegEven =SumNegEven +1; NegEven(SumNegEven)=D(i); end ifmod(D(i),2) == 1 SumNegOdd =SumNegOdd +1; NegOdd(SumNegOdd)= D(i); end end % PositiveNumbers if D(i) > 0 SumPosNeg = SumPosNeg +1; PosNeg(SumPosNeg)=1; ifmod(D(i),2)== 0 SumPosEven =SumPosEven +1; PosEven(SumPosEven)=D(i); end if mod(D(i),2) == 1 SumPosOdd =SumPosOdd +1; PosOdd(SumPosOdd)= D(i); end if D(i)>25 SumBig =SumBig +1; Big(SumBig)=D(i); end end end; % Results PosEven PosOdd NegEven NegOdd Big PosNegRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.