Question
MATLAB For a biomedical experiment, the names and weights of the patients have been stored in a file PatWts.dat (bundled in the .zip file). For
MATLAB
For a biomedical experiment, the names and weights of the patients have been stored in a file PatWts.dat (bundled in the .zip file). For example, the file may look like this:
Darby George 166.2
Helen Dee 143.5
Giovanni Lupa 192.4
Cat Donovan 215.1
Write a script readpatwts that will first attempt to open the file. If the file open is not successful, an error message should be printed. If it is successful, the script will use fgetl to read the data into strings, one line at a time. Do not assume that the number of lines in the file is known. Instead of using a for loop, use a while loop until the end of the file is reached. Then your script will perform the following additional steps: (1) print for each person the name in the form last,first followed by the weight; (2) calculate and print the average weight. Finally, your script will use fclose to close the file and print whether or not the file was successfully closed.
For example, the result of running the script would look like this:
>> readpatwts George,Darby 166.2
Dee,Helen 143.5 Lupa,Giovanni 192.4
Donovan,Cat 215.1
The ave weight is 179.30
File close successful
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started