20) A script stores information on potential subjects for an experiment in a vec
ID: 3653346 • Letter: 2
Question
20) A script stores information on potential subjects for an experiment in a vector of structures called subjects. The following show an example of what the contents might be: >> subjects subjects = 1x3 struct array with fields: name sub_id height weight >> subjects(1) ans = name: 'Joey' sub_id: 111 height: 6.7000 weight: 222.2000 For this particular experiment, the only subjects who are eligible are those whose height or weight is lower than the average height or weight of all subjects. The script will print the names of those who are eligible. Create a vector with sample data in a script, and then write the code to accomplish this. DonExplanation / Answer
clear all clc %not really necessary, but: subjects=struct('name','','sub_id',0,'height',5,'weight',100); %some data names={'Joey','Tom','Mike'}; ids=[111,112,113]; heights=[6.7,4.5,5.5]; weights=[222.2,220.1,221.9]; %load those data for i=1:length(names) subjects(i).name=names{i}; subjects(i).sub_id=ids(i); subjects(i).height=heights(i); subjects(i).weight=weights(i); end %summing heightsum=0; weightsum=0; count=length(subjects); for i=1:count heightsum=heightsum+subjects(i).height; weightsum=weightsum+subjects(i).weight; end %calculate average HAvg=heightsum/count; WAvg=weightsum/count; %find qualifying subjects cnt=1; for i=1:count if(subjects(i).heightRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.