Answer:
The function definition to this question can be defined as follows:
Function definition:%defining method
function [ rep_Pos, pincode_Fix ] = pincode_check( pincode )
pincode_Fix_Temp = pincode; %defining variable that holds a value
rep_Pos_Temp = []; %defining array
for i = 1:length(pincode) %defining a loop to count value
if((i > 1)) & (pincode(i) == pincode(i - 1)) %checking value
rep_Pos_Temp([i]) = i; %store value in rep_Pos_Temp array
else
rep_Pos_Temp([i]) = 0; %array assign as 0
end
end
for i = 1:length(pincode) %loop to count value length
if(rep_Pos_Temp(i) > 0)%check condition
pincode_Fix_Temp(i) = 0; %assign value to 0
end
end
%removing all array value
rep_Pos_Temp = nonzeros(rep_Pos_Temp); %assign value in rep_Pos_Temp
pincode_Fix_Temp = nonzeros(pincode_Fix_Temp); %assign value in pincode_Fix_Temp
rep_Pos = rep_Pos_Temp; %re positing value
pincode_Fix = pincode_Fix_Temp'; % assign value in pincode_Fix
end
Step-by-step explanation:
In the given method definition a method a temporary variable "pincode_Fix_Temp" and an array "rep_Pos_Temp" is declared, which holds the values of the return arrays.
- In the next step, a for loop is declare, that counts the length of the array, and inside the loop, a conditional statement is used, that checks if the index is greater than 1, it will go to array out of scope and causing an error, otherwise, the array is equal to the value, and index value stored in the rep_Pos variable.
- Then another for loop is declared, that checks the values of the rep_Pos variable and see if there are repeated value, so, indexes will be set to zero. At the last step, it removes all the zeros.