Create a script that will prompt the user to enter their desired matrix dimensio
ID: 3568218 • Letter: C
Question
Create a script that will prompt the user to enter their desired matrix dimensions. Then create a matrix of random integers with those dimensions. After that, perform each of the following using loops (Not using that 'min' built in function' but you may use if statements if necessary): ? Find the minimum value in each column. ? Find the minimum value in each row. ? Find the minimum value in the entire matrix. Example Output: Enter the number of rows: 4 Enter the number of columns: 5 mat = 22 33 34 33 14 46 2 38 9 3 40 43 38 36 5 48 47 20 2 42 The overall min is 2 The min of row 1 is 14 The min of row 2 is 2 The min of row 3 is 5 The min of row 4 is 2 The min of column 1 is 22 The min of column 2 is 2 The min of column 3 is 20 The min of column 4 is 2 The min of column 5 is 3Explanation / Answer
m = input('Enter the number of rows: ');
n = input('Enter the number of columns: ');
X = fix(100*rand(m,n));
X
overallMin = 9999;
for i = 1:m
for j = 1:n
if X(i,j) < overallMin
overallMin = X(i, j);
end
end
end
fprintf('The overall min is %i ', overallMin);
for i = 1:m
min = 9999;
for j = 1:n
if X(i,j) < min
min = X(i, j);
end
end
fprintf('The min of Row %i is %i ', i, min);
end
fprintf(' ');
for j = 1:n
minC = 9999;
for i = 1:m
if X(i,j) < minC
minC = X(i, j);
end
end
fprintf('The min of Column %i is %i ', j, minC);
end
-------------------------------
OUTPUT
Enter number of rows: 3
Enter number of columns: 5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.