Given the array A = [2 7 9 7 ; 3 1 5 6 ; 8 1 2 5]

a. assign the even-numbered columns of A to an array called B

b. assign the odd-numbered rows to an array called C

c. convert A into a 4-by-3 array

d. compute the reciprocal of each element of A

e. compute the square-root of each element of A

## Answers (1)

MATHLAB or MATLAB? If you mean MATLAb?

a. B = [];

for i = 1:length(A(1,:))

if rem(i,2) == 0

B(:,i/2) = A(:,i);

end

end

B

b.

C = [];

for j = 1:length(A(:,1))

if rem(j,2) == 1

C((j+1)/2, :) = A(j,:);

end

end

C

c. Taking the transpose and assigning it to A is simple:

A = A'

d. Computing the reciprocal and assigning it to an array called D is simple:

D = 1./A

e. Computing the square-root of each element and assigning to an array called E is also simple:

E = A.^0.5