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

PROBLEM 3. Repeats %------------------------------------------------------------

ID: 3623538 • Letter: P

Question

PROBLEM 3. Repeats
%--------------------------------------------------------------------------
%
% Function Name: removeRepeat
% Inputs (1): - (double) a vector
% Outputs (2): - (double) the input vector or string with all the
% repeats removed
% - (double) vector of indices from the original vector that
% were removed in order to create the output vector
%
% Function Description:
% Given a vector or a string of any length, write a function,
% removeRepeat, that runs through each element in the vector from left to
% right. It will then check and remove duplicate occurrences of any
% previous values in the original vector. Your first output should be the
% input vector with the extra duplicate values removed, and the second
% output should be the index values from which the removed values were
% obtained with respect to the original vector.
%
% For example, given the input vector, [9 8 9 7 6 7 7], the duplicate
% values of 9 and 7 are obtained. Therefore, removing all duplicate
% occurrences of previous values in the original vector, we will remove
% all duplicate values except for the first occurrence in the output
% vector. The final vector will then be: [9 8 7 6], with the second
% output being the indices removed: [3 6 7].
%
% Note:
% - You may not use the unique() function.
%
% Hints:
% - You might find the find() function useful.
% - Thinking outside the box will greatly simplify this problem. Instead
% of removing elements from the original vector, consider an
% alternative approach, in which you begin with two empty vectors, one
% for including all unique numbers and the second for including all the
% indices of duplicates. Through iteration, these two empty vectors
% will gradually be filled with the appropriate numbers. As you move
% through the vector from the 1st to last index, use a clever if
% statement to concatenate all unique numbers to the first output
% vector, and all non-unique numbers' indices to the second output
% vector. Only one loop should be necessary to solve the problem with
% this approach.
%
% Test Cases:
% [removed1 ind1]=removeRepeat([9 8 9 7 6 7 7])
% removed1 => [9 8 7 6]
% ind1 => [3 6 7]
%
% [removed2 ind2]=removeRepeat([0 9 1 4 1 9 9 0])
% removed2 => [0 9 1 4]
% ind2 => [5 6 7 8]
%
% [removed3 ind3]=removeRepeat([1 3 4 88 2 11 89])
% removed3 => [1 3 4 88 2 11 89]
% ind3 => []


%==========================================================================
% PROBLEM 4. Reshaping Vectors
%--------------------------------------------------------------------------
%
% Function Name: myReshape
% Inputs (1): - (double) a row vector of doubles
% Outputs (1): - (double) the elements of the row vector reshaped to form
% an array
%
% Function Description:
% Write a function called "myReshape" that will take in a row vector of
% doubles and reshape it into an array with the following specifications:
%
% - The number of columns in the new array will be equal to the index of
% the *first* zero in the input vector. For example, if the *first*
% zero in the vector is at position three, then the array should have
% three columns.
% - The rows of the array should be filled with the in-order elements
% from the vector.
% - If there are not enough remaining elements in the vector to form a
% complete last row, the function should zero-fill to make it complete,
% i.e. the array should NOT be jagged.
% - If there is not a zero in the original vector, then the function
% should return the input vector unchanged.
% - You must use iteration to solve this problem.
%
% As an example, please look at the following visual example:
%
% illustration_vec = [3 1 4 3 0 1 8 2 7 3 6 4]
% illustration_answer = myReshape(illustration_vec);
% illustration_answer => [3 1 4 3 0
% 1 8 2 7 3
% 6 4 0 0 0]
%
% Notes:
% - You may *not* use the reshape() function.
% - Remember: Vectors are arrays too! They are just arrays where at least
% one of the dimensions is 1.
%
% Hints:
% - The second and third inputs of the find() function may help with
% finding the first zero.
% - Think about what the array would look like if there was a zero at
% (index = 1) of the input vector.
%
% Test Cases:
% arr1 = myReshape([6 2 4 5 0 1 9 3 8 7 6 9 5 4 1 2 3 3 1 2 10]);
% arr1 => [6 2 4 5 0
% 1 9 3 8 7
% 6 9 5 4 1
% 2 3 3 1 2
% 10 0 0 0 0]
%
% arr2 = myReshape([3 1 4 1 5 9 2 6]);
% arr2 => [3 1 4 1 5 9 2 6]
%
% arr3 = myReshape(zeros(1,3))
% arr3 => [0;0;0]

Explanation / Answer

what is to be found out????

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