Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given variable b that contains a row vector of length 10, assign the contents of

ID: 3788186 • Letter: G

Question

Given variable b that contains a row vector of length 10, assign the contents of the odd indices in b to variable odd, and assign the contents of the even indices of b to variable even. (Psst! the plural of index is indices. This has been your SAT vocabulary booster of the day) Examples: Input b = [8 -3 0 7 -6 -3 1 8 7 -2] Output odd = [8 0 -6 1 7] even = [.3 7 .3 8 -2] Solution function [odd even] = OddEvenlnd(b) %replace the line below with code to assign to variable odd the contents in the odd indices of b = [8 -3 0 7 -6 -3 1 8 7 -2]; odd = b([1, 3, 5, 7, 9)]; %replace the line below with code to assign to variable even the contents in the even indices of even = b([2, 4, 6, 8, 10]); end

Explanation / Answer

s=[1,2,3,4,5,6,7,8,9,-3];
evennumbers=s(mod(s,2)==0);
oddnumbers=s(mod(s,2)~=0);
disp(evens);
disp(odds);
comments:


//here s(mod(s,2)==0)gives you out an even numbers and store in evennumber vector..here it check each digit divides by 2 gives remainder
is zero if return zero it stores in evennumbers.
same way which divides by 2 does not leaves remainder 0 it stores in oddnumbers vector.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote