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

23.26 Pincode (Loops) 23.26.1: Pincode (Loops) This tool is provided by a third

ID: 3597272 • Letter: 2

Question

23.26 Pincode (Loops) 23.26.1: Pincode (Loops) 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 0/10 Pincode A pincode consists of N integers between 1 and 9. In a valid pincode code no integer is allow to repeat consecutively. For example, the sequence 1,2,1,3 is valid because even though 1 occurs twice, it is not consecutive. However, sequence 1,2,2,1 is invalid because 2 occurs twice, consecutively Utilize a for loop and branch statements to write a function pinCodeCheck to detect and eliminate all the consecutive repetitions in the row array pinCode. The outputs are two row arrays. The row array repPos contains the positions pinCode where there are consecutive repeats occurs, and the row array pinCodeFix is a valid pincode with all the consecutive repeats removed in pinCode For example: If pincode=[2 9 9 5 8 24989] then [ repPos, pincodeFix ] = pincodecheck( pincode ) produces repPos = pincodeFix = 2 9 2 4 9 9 Your Function Save C Reset MATLAB Documentation 1 function [ repPos, pinCodeFix ] = pincodecheck( pincode ) % Your solution goes here 5 en Code to call your function C Reset 1 [ repPos, pinCodeFix ] = pinCodeCheck( pincode )

Explanation / Answer

pinCodeCheck.m

function [ repPos, pinCodeFix ] = pinCodeCheck( pinCode )
pinCodeFix = [pinCode(1)];
repPos = [];
n = size(pinCode, 2);
  
j = 1;
  
for i = 2:n
if pinCode(i) == pinCodeFix(j)
repPos = [repPos i];
else
pinCodeFix = [pinCodeFix pinCode(i)];
j = j + 1;
end
end
end

run on console

pinCode = [2 9 9 5 8 2 4 9 8 9];
[ repPos, pinCodeFix ] = pinCodeCheck( pinCode )

Sample output

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