Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A script stores information on potential subjects for an experiment in a vector

ID: 3801938 • Letter: A

Question

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:

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 and store those names in a cell array. Create a vector with 3 sample subjects, then write the code to accomplish this. Don’t assume that the length of the vector is known; the code should be general.

Explanation / Answer

Answer:

subjects(5) = struct('name', 'Joey', 'sub_id', 111, 'height', 6.7, 'weight', 222.2);
subjects(1) = struct('name', 'Fred', 'sub_id', 112, 'height', 5.3, 'weight', 262.0);
subjects(2) = struct('name', 'Scott', 'sub_id', 113, 'height', 6.2, 'weight', 186.3);
subjects(3) = struct('name' , 'Erik' , 'sub_id' , 114, 'height' , 5.6, 'weight' , 161.9);
subjects(4) = struct( 'name' , 'Bob' , 'sub_id' , 115, 'height' , 4.4, 'weight' , 255.4);
subjects_total = length(subjects);
input = sum([subjects.height])/subjects_total;
read = sum([subjects.weight])/subjects_total;
worth = [subjects.height] < input | [subjects.weight] < read;
fprintf( ' Eligible are: ' )
fprintf( '%s ' , subjects(worth).name);
fprintf( ' Not Eligible are: ' )
fprintf( '%s ' , subjects(~worth).name);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote