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

This needs to be solved in MATLAB: Problem 1. a) Write a function matcolsum usin

ID: 643793 • Letter: T

Question

This needs to be solved in MATLAB:

Problem 1. a) Write a function matcolsum using nested for loops that will read a matrix as input argument, sum each individual column of a matrix, and return a row vector containing the sum as the output argument. (DO NOT use MATLAB built-in function sum.) The function header is: function outsum = matcolsum (mat) For example, if we have a matrix mat = 3 4 5 2 5 7 then the returned row vector outsum should be outsum = 5 9 12 b) Use the MATLAB built-in function (command) to get the same output.

Explanation / Answer

a)

function outsum = matcolsum( mat )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here

[m,n] = size(mat);
outsum = zeros([1 n]);
for j=1:n
    sum = 0;
    for i=1:m
        sum = sum + mat(i,j);
    end
    outsum(j)=sum;
end

end

b) sum(mat)

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