MATLAB Write a function that returns a matrix that is a colu
MATLAB: Write a function that returns a matrix that is a column vector containing the product of the numbers on the rows of the matrix that contain integers.
Solution
Matlab Code
function [ Output ] = product( A )
[p , q] = size(A);
k=1;
for i=1:p
for j=1:q
k = k*A(i,j);
Output(i,1)=k;
end
k=1;
end
end
Sample Output
>> A = [1 2 3; 4 5 6; 7 8 9];
>> product(A)
ans =
6
120
504
