943 me 2115 intro to programmingfall Problem Description Wri

943 me 2115 intro to programming-fall. Problem Description Write a MATLAB M-file named ColAvg, which will Accept any input matrix, and report the column averages Returns as output the average of all the elements in the matrix. The averages should be the same asusing MATLAB built-in function mean, but do not use this function. Hint: The code for this problem will be similar to sumonlypos.m found in yourtextbookon page 160. 10 The average The average of 3333 joshua szymansk

Solution

% matlab code average of matrix column and total average


function avg = ColAvg(A)
    [row, column] = size(A);
    avg = 0;
    for i = 1:column
        colavg = 0.0;
        for j = 1:row
            colavg = colavg + A(j,i);
            avg = avg + A(j,i);
        end
        colavg = colavg/row;
        fprintf(\"The average of column %d is %f\ \",i,colavg);
    end
  
    avg = avg/(row*column);
end
A = input(\"Input Matrix: \");
ans = ColAvg(A);
fprintf(\"ans = %f\ \",ans);

%{
output:

Input Matrix: [5 -4 6 -5; 10 -8 -2 -7; 1 2 -9 -5]
The average of column 1 is 5.3333
The average of column 2 is -3.3333
The average of column 3 is -1.6667
The average of column 4 is -5.6667
ans = -1.3333


%}

 943 me 2115 intro to programming-fall. Problem Description Write a MATLAB M-file named ColAvg, which will Accept any input matrix, and report the column averag

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site