Course name: BMEN 1300
Section: 001
Date: 28SEP23
Homework assignment 4
Full name: Vince Powers
Please note that every single file you submit to eLearning has to have course name, section, date,
assignment number, and your full name on top of it. For m-files, use comment format to include the
above information.
We are available to help you during our office hours. Feel free to stop by at any office hours (not
necessarily your group TA’s office hours).
Study chapters 2 (mainly loops and jumps) of your MATLAB textbook for your quiz. Please
remember that our weekly quizzes will be always held on Tuesdays, unless we announce
otherwise.
1. Write a MATLAB live script to solve Exercise 2.12 of your MATLAB textbook. No flowchart is
needed for this question. Save your file as “HW5Ex2_12FirstnameLastname.mlx”. Export it as a
pdf. To make the grading easier, copy the lines of code you wrote and paste them here. Also add
the output of your code (e.g., a screenshot).
2. x=0
3. nPrimes=0
4. while (nPrimes<20)
5. if(isprime(x))
6. % if(x>50)
7. % break
8. % end
9. if(x<10)
10. x=x+1
11. continue
12. end
13. disp(x)
14. nPrimes=nPrimes+1
15. end
16. x=x+1
17. end
18.
19. Sketch a flowchart and write a MATLAB live script to solve the following question:
The end diastolic volume (EDV) and end systolic volume (ESV) of the left ventricle of the heart
refer to the volume (in mL) of blood just prior to the heart beat, and at the end of the heartbeat,
respectively. The ejection fraction (EF) is the fraction of blood pumped out from the heart in
each beat, and can be computed from the EDV and ESV as follows:
EDV −ESV
EF=
EDV
The file edv_esv.mat contains EDV and ESV values for some patients. Write a MATLAB Live Script
to read in these data (load edv_esv.mat), and compute EF values for each patient. Then display
the EDV, ESV, and EF values for all patients. Whenever EF is infinity or undefined, your script
must show a message indicating that. Hint: use a for-loop that runs from 1 to the length of your
EF variable (check MATLAB help for the function length). Below is the expected output of your
code:
For EDV: 61 and ESV: 120
EF: -0.96721
For EDV: 49 and ESV: 136
EF: -1.7755
For EDV: 64 and ESV: 89
EF: -0.39062
For EDV: 0 and ESV: 111
EF is infinity.
For EDV: 119 and ESV: 160
EF: -0.34454
For EDV: 0 and ESV: 0
EF is not a number.
Add a copy/picture of your flowchart here. Save your file as “[Link]”.
Export it as a pdf. To make the grading easier, copy the lines of code you wrote and paste them
here. Also add the output of your code (e.g., a screenshot).
load('edv_esv.mat')
for x=1:length(EDV)
EF=(EDV(x)-ESV(x))/EDV(x);
if isinf(EF)
disp(['For EDV: ',EDV(x),' and ESV: ',ESV(x),' EF is infinity.'])
elseif isnan(EF)
disp(['For EDV: ',EDV(x),' and ESV: ',ESV(x),' EF is not a number'])
else
disp(['For EDV: ',num2str(EDV(x)),' and ESV: ',num2str(ESV(x)),' EF:
',num2str(EF)])
end
end
20. A script to solve Exercise 3.6 of your MATLAB textbook is provided below but it needs to be
edited in order for it to actually solve the exercise. A ? has been placed in the code for you to fill
in what is necessary for this code to work properly. Add a line of code which displays the
diseases prior to saving.
clear;
clc;
load('[Link]')
for (x=1:length(?))
%% get disease name and change to lower case
s = char(?); % easier to work with char array!
s = lower(?);
%find all spaces in disease name
p = strfind(?, ' ');
% change first letter of each word to upper case
s(1) = upper(?(1));
for y=p
s(y+1) = upper(s(y+1));
end
diseases(?) = string(?);
end
% save
save('[Link]', 'diseases');
Save your file as “HW5Ex3_6FirstnameLastname.m”. Export it as a pdf. To make the grading
easier, copy the lines of code you wrote and paste them here. Also add the output of your code
(e.g., a screenshot).
I could not figure out how to get this code to work, could I please get some feedback on how to improve
this?
clear;
clc;
load('[Link]')
for (x=1:length(diseases))
%% get disease name and change to lower case
s = char(diseases); % easier to work with char array!
s = lower(s);
%find all spaces in disease name
p = strfind(diseases, ' ');
% change first letter of each word to upper case
s(' ') = upper(s(' '))
for y=s(1)
s(y+1) = upper(s(y+1))
end
diseases(x) = string(x)
end
% save
save('[Link]', 'diseases')
Hint: This is the format of output we are looking for:
"Breast Cancer" "Colon Cancer" "Lung Cancer" "Epilepsy" "Bacterial Pneumonia"
"Viral Pneumonia" "Myoplasma Pneumonia" "Coronary Artery Disease"
The MATLAB functions that could be helpful are char, string, lower, upper, and strfind. Check
MATLAB help for them.
A good code is the one which works with a disease array with any length and with any
number of words for a disease name.
21. Save this file as a pdf and submit it to eLearning along with your mlx and pdf files.
Well done!