Question

In: Computer Science

For this assignment, using MATLAB you are to read from an Excel file “theInputFile.xlsx” an undetermined...

For this assignment, using MATLAB you are to read from an Excel file “theInputFile.xlsx” an undetermined number of rows and columns.

The first task of your program is to find out if the data in the file is in a square matrix. If it is not square the program will give us a statement telling us the data is not complete.

If it is square then the program proceeds and will find the average of the rows one row at a time using your average function that you will create. However, for a row average to be considered valid the row average must be greater than or equal to the average of the diagonal of the matrix.

(Going from the upper left-hand corner to the lower right-hand corner)

The output should look like the following... either a statement must be outputted stating the data is not complete or if it is complete it will look like the following.

Error using test (line 8)
Something is wrong

or

The average for row 1 is 23.5

The average for row 2 is 3.4

The average for row 3 is not Valid

The average for row 4 is 12.8
.
.
.

Solutions

Expert Solution

Code to copy along with screenshots of code and output are provided.

Please save the code to matlab script file before executing.
Please refer to screenshots to understand the indentation of code.
If you have any doubts or issues. Feel free to ask in comments
Please give this answer a like, or upvote. This will be very helpful for me.
================================================================

Screenshots of Code :

"theInputFIle.xlsx" ----- (Please save the excel file into same folder as matlab script file):

Screenshots of Output :

Code to copy:

clc;

% name of our xlsx file
filename = 'theInputFile.xlsx';
% reading file and storing values into A
A = xlsread(filename);
% calculating length and width of A
[row,column] = size(A);

% if square matrix
if row == column
% call average(A) function
average(A);
  
else
% otherwise
fprintf("The data int the file is not complete!!");
  
end

% function to calculate averge of rows
function z = average(X)
z = 0;

% calculating number of rows and columns
[row,column] = size(X);
% declaring diagonal_sum variable
diagonal_sum = 0;
% declaring row_sum variable
row_sum = 0;
% calculating diagonal_sum using for loop
for i = 1:column
diagonal_sum = diagonal_sum + X(i,i);
end
  
% calculating sum of each row and displaying it using for loop
for i = 1:column

% calcuating row_sum of row = i
for j = 1:row
row_sum = row_sum + X(i,j);
end
% if row_sum greater than equal to diagonal_sum
if row_sum >= diagonal_sum
fprintf("The average for row %d is %.3f \n", i, row_sum);
else
% otherwise
fprintf("The average for row %d is invalid\n", i);
end

row_sum = 0;
end

end

  

--------------------------XXXXXXX----------------------------------------------------


Related Solutions

Read the assignment and answer the questions. You must also upload your Excel file, Word document...
Read the assignment and answer the questions. You must also upload your Excel file, Word document or pdf showing your work. Bodacious Building Co. is considering four different acquisition methods for obtaining pickup trucks. If the contractor’s MARR is 6%, which alternative do you recommend? The alternatives are: Immediate cash purchase of the trucks for $22,500 each, and after five years sell each truck for an estimated $4,900. Lease the trucks for five years for $4,000 per year paid at...
In this assignment, you shall create a complete C++ program that will read from a file,...
In this assignment, you shall create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name Next it will need to read three integer values that will represent the 3 exam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student. Below...
For this assignment, you will read the scenario and then use the provided Excel and Word...
For this assignment, you will read the scenario and then use the provided Excel and Word document templates to complete your assignment before uploading them to the assignment submission area. Scenario Larry and Beth are both married, working adults. They both plan for retirement and consider the $6,000 annual contribution a must. First, consider Beth's savings. She began working at age 20 and began making an annual contribution to her IRA of $6,000 each year until age 32 (12 contributions)....
JAVA Assignment: Project File Processing. Write a program that will read in from input file one...
JAVA Assignment: Project File Processing. Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of...
In this lab, you open a file and read input from that file in a prewritten...
In this lab, you open a file and read input from that file in a prewritten C++ program. The program should read and print the names of flowers and whether they are grown in shade or sun. The data is stored in the input file named flowers.dat. Instructions Ensure the source code file named Flowers.cpp is open in the code editor. Declare the variables you will need. Write the C++ statements that will open the input file flowers.dat for reading....
This assignment asks you to set up an Excel budget spreadsheet file that automatically prepares the...
This assignment asks you to set up an Excel budget spreadsheet file that automatically prepares the master budget for a company, given sales projections and information on beginning balances, production requirements, desired ending inventories, etc. Information on developing the budgets appears in Chapter 8 of your text, and examples of budget worksheets appear in the schedules throughout the chapter. Data Glamour Inc. produces and sells lady handbags. Below is information on its activities for the next few months. Sales projections...
Using JAVA The following code is able to read integers from a file that is called...
Using JAVA The following code is able to read integers from a file that is called "start.ppm" onto a 3d array called "startImage". Implement the code by being able to read from another file (make up any file name) and save the data onto another 3d array lets say you call that array "finalImage". The purpose of this will be to add both arrays and then get the average Save the average onto a separte 3darray,lets say you call it...
Using OOP, write a C++ program that will read in a file of names. The file...
Using OOP, write a C++ program that will read in a file of names. The file is called Names.txt and should be located in the current directory of your program. Read in and store the names into an array of 30 names. Sort the array using the selection sort or the bubblesort code found in your textbook. List the roster of students in ascending alphabetical order. Projects using global variables or not using a class and object will result in...
Interpolation Filters. Write a Matlab program to read and upsample the linked voice_samp_8k.wav file (below --...
Interpolation Filters. Write a Matlab program to read and upsample the linked voice_samp_8k.wav file (below -- sampled at Fs=8000 samples per second) by an integer factor L (you can choose, probably in the range from 3 to 7 or so). Then use interpolation filtering to produce the following outputs and listen to them and plot short segments (~50-100 samples) of these outputs: (i) upsample only with no interpolation filtering, (ii) hold interpolation implemented directly as a causal FIR filter, (iii)...
You have to write a program that will read an array from a file and print...
You have to write a program that will read an array from a file and print if the numbers in the file are right truncatable primes. A right truncatable prime is a prime number, where if you truncate any numbers from the right, the resulting number is still prime. For example, 3797 is a truncatable prime number number because 3797, 379, 37, and 3 are all primes. Input-Output format: Your program will take the file name as input. The first...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT