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

All that is needed is for you to write the code for the problem shown in the pic

ID: 3767707 • Letter: A

Question

All that is needed is for you to write the code for the problem shown in the picture below using the given flowchart and the alternating function code also given below.

I am requesting the code to be written in matlab and copy and pasted here following the above guidlines.

ALTERNATING FUNCTION CODE:

function [ V_out ] = Lab_11( V, target, dest )
%LAB_11 Moves element of vector V defined by 'target' into the position
%       defined by 'dest'
%  
%   Inputs:     V       = input vector
%               target = target element to move
%               dest    = destination to place the target element
%  
%   Outputs:    V_out   = the output vector

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-- Check input for errors
N = length(V);

if target < 1 || target > N
    error('Error: the specified target position (%d) is out of bounds. ', target);
elseif dest < 1 || dest > N
    error('Error: the specified destination position (%d) is out of bounds. ', dest);
end

%-- Fill output vector with the input vector
V_out = V;

%-- Pull the target element out and store in temporary storage
target_value = V(target);

%-- Check if the destination is before or after the specified target
if target > dest   %-- Move the target before the destination
   
    range = dest+1:target;
    V_out(range) = V(range-1);

else                %-- Move the target after the destination

    range = target:dest-1;
    V_out(range) = V(range+1);
   
end

%-- Replace the destination value with the target value
V_out(dest) = target_value;

end

Explanation / Answer

Program: