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

Matrix Software needed: MATLAB R2016a Objective: With Matlab, Use While loop to

ID: 3810654 • Letter: M

Question

Matrix

Software needed: MATLAB R2016a

Objective:

With Matlab, Use While loop to allow program to cycle.   For Loop to examine arrays (Matrices). Need to find Sum and average as well as Max and Min values. See requirements below for more specifics. Input and Output to communicate with User.

I recommend you run the Dialog_Fill_Matrix.m program and understand how it works.   Then incorporate this code into your program.

Requirements:

1. The Program should loop until the user chooses to exit.   Use the accompanying DIalog_Fill_Matrix.m program to learn how to enter data into a matrix M=(R,C). Matrix are 2 dimensional arrays.

2. Ask user to input a matrix. Calculate the sum of each column and average of each column and display the sum as a vector and the average as a vector.   Then find the Max value and Min value in the entire array and display them. Then repeat program. Note Row (R) >1 and Column (C) >1.

3. NOTE: for Sum, Average, Min, and Max DO NOT USE the functions by these names that are in MATLAB.   I want to use a for loops to examine each value in the vector or array and then do the calculations.  

4. For the program loop and other examples please use the Survey program code to kick start your code.

5. NOTE ALSO for Min and Max you cannot use numbers like 0 or 1000 when comparing elements to find Min and Max. What if you had negative numbers or numbers outside that range.   HINT: You can you use a vector or array element instead of a preset number, if so, which one would you choose??

Explanation / Answer

userinput=1;

while(userinput==1)
prompt = 'enter a matrix ';
x = input(prompt);
sums=[];
s=0;
a=0;
[rows,cols] = size(x)
index=1;
averages=[];
minimum=x(1,1);
maximum=x(1,1);

for co=1:cols

for r=1:rows
  
s = s + x(r,co);

if(x(r,co)<minimum)
minimum=x(r,co);
end

if(x(r,co)>maximum)
maximum=x(r,co);
end

end
  
  
  
sums(index)=s;
averages(index)=(s/rows);
index=index+1;
s=0;
end

sums
averages
minimum
maximum

prompt='do you want to run again (1/0)';
userinput=input(prompt);
end