Question

The data is as follows:

1/Joe Bloggs/118/75

2/Josephine Bloggs/163/91

3/Zhang San/105/81

4/Anders Andersen/158/103

5/Erika Mustermann/131/84

6/Ola Nordmann/117/68

7/Jan Kowalski/127/88

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Important Note: Please ensure that you put the input text file "bpdata.txt" inside the Matlab's workspace directory before running the program.

Matlab Code :

% Clearing the Workspace
clc
clear all

%% Main Program begins
filename = 'bpdata.txt';
fid = fopen(filename);
% checking whether file was opened successfully or not
if fid == -1
    fprintf('Error! File ''%s'' not found\n', filename);
    return
end

% reading the text file using the delimiter '/'
data  = textscan(fid, '%d%s%d%d', 'Delimiter', '/');

% closing the file
fclose(fid);

% printing the stats
fprintf('ID\t\tName\t\t\t\tBP Classification\n')
disp('----------------------------------------------')

for i = 1:numel(data{3})
    sys = data{3}(i);
    dias = data{4}(i);
    name  = data{2}{i};
    id = data{1}(i);
    bpType = getBloodPressureType(sys, dias);
    fprintf('%d\t\t%-18s\t\t%-16s\n', id, name, bpType)
end


%% User defined function to return the Blood Pressure type
% Returns a type classification based on input systolic and diastolic pressure
function [type] = getBloodPressureType(sys, dias)
type = 'Undefined';
if ( sys > 90 && sys < 120 ) && (dias > 60 && dias < 80)
    type = 'Ideal';
elseif ( sys > 120 && sys < 140 ) && (dias > 80 && dias < 90)
    type = 'Pre - High';
elseif ( sys > 140 && dias > 90 )
    type = 'High';
end
end

OUTPUT :

Command Window ID Name BP Classification Joe Bloggs Josephine Bloggs Zhang San Anders Andersen Erika Mustermann ola Nordmann

Add a comment
Know the answer?
Add Answer to:
The data is as follows: 1/Joe Bloggs/118/75 2/Josephine Bloggs/163/91 3/Zhang San/105/81 4/Anders Andersen/158/103 5/Erika Mustermann/131/84 6/Ola...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT