i solved most of it. i did till part G here is my code clc clear all num_rows=in
ID: 3763262 • Letter: I
Question
i solved most of it.
i did till part G
here is my code
clc
clear all
num_rows=input('Enter the number of rows for a matrix: ');
num_columns=input('Enter the number of columns for a matrix: ');
mat=randi([-50, 50], num_rows,num_columns );
disp(mat)
total=0;
total_all = 0;
for r=1:num_rows
for c=1:num_columns
total=total+mat(r,c);
end
fprintf('Total of row #%d is %d ',r, total)
total_all = total_all+total;
total = 0;
sum_total=total_all;
end
mean_total=mean(mat);
fprintf('Total of all element is %d ',sum_total )
fprintf('Mean of all element is %.0f ', mean_total)
but im not sure about last line in the code
Explanation / Answer
Solution:
min_all=mat(1,1);
pos_row_all=1;
pos_col_all=1;
for i=1:num_columns
min_each_col=mat(1,i);
row_pos=1;
for j=2:num_rows
if(min_each_col>mat(j,i))
min_each_col=mat(j,i);
row_pos=j;
end
end
fprintf('The minimum of column %d is %d and is in row %d ',i,min_each_col,row_pos);
if(min_each_col < min_all)
min_all=min_each_col;
pos_row_all=row_pos;
pos_col_all=i;
end
end
fprintf('The minimum of all the elements is %d ',min_all);
fprintf('The minimum is in row %d and column %d ',pos_row_all,pos_col_all);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.