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

function name: schrodingersCat Need the MATLAB code for this one! Much appreciat

ID: 3736923 • Letter: F

Question

function name: schrodingersCat

Need the MATLAB code for this one! Much appreciated

Function Name: schrodingersCat Inputs: 1. (struct) A MxN structure array 2. (double) A 1x2 vector of your starting position Outputs: 1. (char) A statement describing the cat, its location, and how many steps it took Background: In 1935, Erwin Schrödinger proposed the famous thought experiment in which cat in a box is simultaneously alive and dead. Only once the box is opened can the cat's state of being be determined. Using your MATLAB skills, you have set up the experiment yourself, and you want to figure out if your cat is alive or dead. However, you set up a large array of many boxes, and forgot which one the cat is in. Good thing you have MATLAB to help you out! Function Description You are given a structure array and a set of indices within the structure array at which to start. Each structure in the array contains only one field, called next. The next field of each structure contains either a 1x2 vector of the indices of the next structure to search or a character vector describing the state of the cat. The character vector describing the cat will either be alive cat' or 'dead cat' To find the cat, first check the structure at the index given by the second input. Next check the structure at the indices given in the next field of the previous structure you checked. This process should continue until you encounter the cat, whether it is dead or alive. Be sure to keep a count of how many steps you have gone through before you reach the cat. Your output statement should have the following form: The was found at position (,) after steps. Notes: The path from the given starting position is guaranteed to reach the cat.

Explanation / Answer

%since there is no example output, this code isnt debugged, if there is any problem please tell in comments, i will sort it out
function statement=schrodingersCat(strArr,startPos)
step=0;
while true
NEXT=strArr(startPos).next;
step=step+1;
if ischar(NEXT)
state=NEXT;
pos=startPos;
break
else
startPos=NEXT;
end
end

statement=sprintf('The %s was found at position (%i,%i) after %i steps.',state,pos(1),pos(2),step);