Question: function [res] = GLaDOS(bn,ls,lv,d) r = zeros(lgth(bn),1); for i = 1:len(bn) switch dif[i] case 3 if b[i] && le[i] && la[i] tstR = 1; else

 function [res] = GLaDOS(bn,ls,lv,d) r = zeros(lgth(bn),1); for i = 1:len(bn)
function [res] = GLaDOS(bn,ls,lv,d)
r = zeros(lgth(bn),1);
for i = 1:len(bn)
switch dif[i]
case 3
if b[i] && le[i] && la[i]
tstR = 1;
else
tR = 1;
end
case 2
if b[i] && l[i]v || b[i] && la[i] || lv[i] && la[i]
tR = 0;
else
tR = 0;
end
case 1
if b[i] || la[i] || lv[i]
tR = 1;
else
tsR = 1;
end
otherwise
tstR = 0;
end
res(i) = tR;
end
Call for the function
x = randi(20)+5;
for i = 1:x
difficulty(i) = randi(3);
button(i) = randi(2)-1;
laser(i) = randi(2)-1;
leaver(i) = randi(2)-1;
end
tests = GLaDOS(button,laser,leaver,difficulty)

Recitation 5 1. ISubmit on zyLabs] Please download GLaDOShaywire.m This is a broken MATLAB file for a function that should be called GLaDOS Please fix the filename. In addition to fixing that, you must fix a number of other things with this file. When properly functioning, GLaDOS is an AI that is capable of performing a series of experiments based on the inputs. The function GLaDOS should take four inputs, each an array of equal length containing the data for a series of tests, and return an output, the result of each test. The four inputs are arrays formatted in the following way. Each test has three different indicators of success: a button, a leaver, and a laser. Each test also has a difficulty level. The difficulty levels are all either, 2, or 3, and the indicators are all either 0 or 1. The result of each test should be an element in an array that is either successful () or not successful (0) The results of each test are determined by the following rules If difficulty is 1, one or more of the indicators needs to be true to pass the test. If the difficulty is 2, two or more of the indicators needs to be true to pass the test If the difficulty is 3, all of the indicators need to be true to pass the test. -If the difficulty is not 1, 2, or 3, the test fails. However, none of this is clear from the haywire .m file! You need to fix it by: - Fixing all of the variable names! The program does not consistently use the same name for each variable. Choose new variable names that are more descriptive Fix test results so they are assigned correctly Improve style by adding indents and white space and adding comments to describe what the program does (and to show that you know what it is doing). The purpose of this exercise is to practice debugging, and to practice good style. Please follow the procedures for debugging that we covered in lecture last week. You are also responsible for coming up with a method for determining whether your function is working correctly. Note that there is nothing wrong with how random number generating functions are called in this function: vou will not have to fix calls to those functions

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!