Matlab has some built-in functions that we have already used, such as sin(x), pl
ID: 1766014 • Letter: M
Question
Matlab has some built-in functions that we have already used, such as sin(x), plot, etc. Type help function and read the documentation and examples on how to create functions in Matlab. Create a function called custom matrix.m that take two parameters, the matrix number of rows (1) and columns (G). The output of your function should be a matrix called SM. The elements of SM(nt,n) where m-n should be (m.n)The elements of SM(n,n) where m >n should be (m). The elements of SM(m.n) where n > m should be n. An example of your function output when i-4 and j 4 is provided below 1 23 4Explanation / Answer
function SM = customer_matrix(m,n)
SM=ones(m,n);
if m==n
for i=1:m
for j=1:m
SM(i,j)=i.*j;
end
end
elseif m<n
SM=n.*SM;
else
SM =m.*SM;
end
end
--------
>> customer_matrix(2,5)
ans =
5 5 5 5 5
5 5 5 5 5
>> customer_matrix(10,5)
ans =
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
>> customer_matrix(5,5)
ans =
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25