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

I am doing this code and I don’t know what wrong with it please can someone chec

ID: 3588561 • Letter: I

Question

I am doing this code and I don’t know what wrong with it please can someone check and fix it
.IArray and Conditional Statement 2 Help/FAQ LAB ACTIVITY 5.11.1: Array and Conditional Statement This tool is provided by a third party. Your activity is always recorded but you may need to refresh the page to fill in the banner Array and Conditional Statement Write a function that takes an array as an input, and returns an array as an output. Your tunction should check to make sure that the array has more than one element It it does not, t should return an empty array If the array has more than one element, your output should be an array with two elements. The first element should be the frst element ot the input array. The second element should be the last element of the input array Please look up the "iength" tunction in MATLAB to heip you with this problem. Save ResetMATLAB Documentation Your Function function out = firstLast (in) if length(in) 0 out = [] else out (1) in(1); out (2) in(length (in)); = : end C Reset Code to call your function testi firstlast(4)

Explanation / Answer

Hi,

The mistake is the length of the array should be more than one. you are checking only for the length zero.you should check for length 1 also.

if length(in) ==0 or length(in)==1

out =[]

else

out[1]=in(1);

out[2]=in(lenght(in));