Write a function called interleave to interleave two row arrays of equal length. Ex: For row arrays arrayOne and arrayTwo, the output row array is arrayThree = [arrayOne(1), arrayTwo(1), arrayOne(2) ,arrayTwo(2), …]. The function should work for rows of any length. Hint: Create a new array by concatinating arrayOne and arrayTwo, then flattening the array to finally end up with the desired row array. No internal functions are needed. Ex: Flattening a=[1,2;3,4] gives [ 1; 3 ; 2; 4]. Restrictions: For and while loops should not be used.

Respuesta :

Answer:

function [ repPos, pinCodeFix ] = pinCodeCheck( pinCode )

      pinCodeFixTemp = pinCode;

      repPosTemp = [];

  for i = 1:length(pinCode)

      if((i > 1)) & (pinCode(i) == pinCode(i - 1))

          repPosTemp([i]) = i;

      else

          repPosTemp([i]) = 0;

      end

  end

  for i = 1:length(pinCode)

      if(repPosTemp(i) > 0)

          pinCodeFixTemp(i) = 0;

      end

  end

  repPosTemp = nonzeros(repPosTemp);

  pinCodeFixTemp = nonzeros(pinCodeFixTemp);

  repPos = repPosTemp';

  pinCodeFix = pinCodeFixTemp';

Following are the MATLAB code to the given question:

Code:

function arrayThree=interleave(arrayOne,arrayTwo)

% Creating a 2-D matrix by concatenating arrayOne and arrayTwo

C1=[arrayOne;arrayTwo];

% Flatten it to get a column vector

arrayThree=C1(:);

% Take transpose to get a row vector

arrayThree=arrayThree';

end

Output:

Please find the attached file.

Learn more:

brainly.com/question/14703381

Ver imagen codiepienagoya
ACCESS MORE