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

Using Matlab: F unction Name: vecResize Inputs: (double) A vector of length N (d

ID: 667985 • Letter: U

Question

Using Matlab:

Function Name: vecResize

Inputs:

(double) A vector of length N

(double) A scalar value by which the vector should be stretched or compressed

Outputs:
1. (double) The new stretched/compressed vector

Function Description:

Write a function in MATLAB called vecResize() that inputs a vector with at least one element and a value by which the vector should be stretched or compressed. This function will output a new vector that has been resized based on the scaling factor given in the second input. If the scaling factor is greater than 1, then the vector should be stretched by adding duplicate elements. If the value is less than 1, then the vector should be compressed by removing elements. If the value is exactly 1, then no change should be made to the vector.

For example, if the following values were input:

then the resulting vector would be stretched by a factor of two by adding duplicate elements:

newVec => [0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 5, 5, 8, 8, 13, 13] However, if scalingFactor = 1/2, then the vector would be compressed by a factor of two

by removing elements from the vector:

Your function should be able to account for any positive, non-zero scaling factor.

Notes:

The input vector is guaranteed to contain at least one element.

The linspace() function, in conjunction with the round() function and numerical

indexing, are useful in solving this problem.

Explanation / Answer

function y= vecResize(x)

double x[10]

N= length(x)

int i=1;

while i< N

prompt('please enter the numbers you want' );

x= input(prompt)

i++;

end

prompt1('eneter the scalar value to make the array streched or compressed');

double z= input (prompt1)

if (z >1)

int a=2;

x=(1 : N) '

double r = repmat (x,1,a) ' ;

r = r(:);

sprintf('%d', r);

else if (z<1)

double x2 = unique (x)

int j=1;

while ( j< (N/2))

x2= unique (x);

j++;

end

sprintf( '%d', x2);

else if (z==1)

sprintf ('%d', x);

end

fclose ();

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