
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
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 :

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...