In: Computer Science
MATLAB
Given a 20x20 matrix named G and a 20x1 vector named H, multiply the elements in the 14th column of G by the values in H (element-by-element multiplication, not a multiplication table).
CODE
function result = doIt(G, H)
for i = 1:20
G(i, 14) *= H(1,14);
end
result = G;
end
G = randi([1 9], [20 20])
H = randi([1 9], [1 20])
result = doIt(G, H)
OUTPUT
G =
1 9 6 5 7 3 6 1 3 9 3 9 2 3 6 8 3 5 2 6
7 1 8 4 8 3 3 5 8 3 1 6 3 6 7 1 5 4 7 9
9 8 4 8 4 2 2 2 4 2 3 2 2 7 8 7 5 6 8 6
1 1 2 6 1 3 1 2 5 9 3 9 2 6 1 6 6 8 5 5
7 4 5 7 9 1 3 1 7 5 7 5 5 8 3 8 5 2 7 3
8 7 8 7 3 8 3 6 1 6 9 1 2 3 8 2 2 8 3 4
5 5 5 7 7 6 4 2 3 6 8 6 7 5 7 9 9 8 2 9
1 9 1 8 1 2 3 3 3 6 1 3 6 5 1 4 1 5 2 5
1 5 6 1 8 7 8 4 4 6 2 5 6 8 4 6 7 4 7 3
7 3 4 4 2 2 4 2 4 3 7 5 5 3 8 7 2 1 1 2
5 1 8 8 8 3 5 5 8 1 8 9 8 7 3 3 3 8 6 3
1 9 5 9 3 6 6 8 9 1 2 3 9 1 8 5 9 4 7 9
3 5 9 5 9 2 4 3 6 3 2 8 2 5 6 3 6 8 2 5
9 1 4 7 2 4 9 9 9 7 4 7 5 6 1 2 3 6 5 7
7 2 2 7 8 4 3 8 5 6 6 5 9 5 3 4 5 1 3 6
9 2 2 1 4 9 1 1 6 1 9 5 7 6 6 9 6 8 7 3
8 1 5 1 1 7 5 3 5 6 7 9 4 2 2 3 1 6 3 3
6 8 8 8 5 4 1 6 6 8 9 7 7 1 8 4 9 8 7 3
9 3 5 1 2 2 9 6 9 5 1 6 6 4 9 4 6 6 1 9
9 1 6 5 4 1 7 6 5 1 4 5 6 1 7 6 4 6 8 8
H =
8 2 7 4 6 1 3 2 6 3 2 7 5 4 3 4 9 7 5 1
result =
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