A script stores information on potential subjects for an experiment in a vector of structures called subjects. The following shows an example of what the contents might be:
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:8| Question number:20.8
All Answers
total answers (1)
Ch8Ex20.m
% create vector of structures on potential subjects for an
% experiment, calculate ave height and weight, and
% determine and print eligible participants
subjects(3) = struct('name','Mary','sub_id',363,'height',5.1,...
'weight',110);
subjects(1) = struct('name','Joey','sub_id',111,'height',6.7,...
'weight',222.2);
subjects(2) = struct('name','Pat','sub_id',221,'height',5.9,...
'weight',165);
%calculate the average height and weight
avgheight = sum([subjects.height])/length(subjects);
avgweight = sum([subjects.weight])/length(subjects);
%find and print the eligible participants
disp('Eligible Subjects:')
for i = 1:length(subjects)
if subjects(i).height < avgheight || subjects(i).weight <
avgweight
fprintf('%s\n',subjects(i).name)
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer