You are to create a matlab function that has the following f

You are to create a matlab function that has the following form: function [K y] = FindMinJump1(x) where the lone input argument x is a vector of real numbers. Make sure your code is properly documented as described on the website. The outputs describe where in vector x the minimum “jumps” occur for consecutive vector elements, in absolute value. That is, the output K is the size of the smallest jump and the vector y are the left-hand-side indexes where the smallest jump(s) occur. It is possible that the vector may have more than one jump at the minimum so the vector y may have more than one index value. For example, if x = [1 2 5 0 2 3]; Then the minimum “jump” occurs between the 1st and 2nd elements, with the value 1, and also between the 5th and 6th elements, when stepping from left to right. It doesn’t matter if the jump is positive or negative when looking at the vector from left to right. Only the absolute value of the jump is considered. The function should output K = 1; as well as the vector y = [1 5]; where the 3 indicates the “left” index of where the jump occurred. If the x vector is empty or has only one element, return the empty vector for both K and y. For this function, use only the basic constructs such as for... end, if... else... end, etc. You are NOT to use the matlab function find.

Solution

Code:

function [K y]=FindMinJump1(x)

% Calculating jump between consecutive elements

for i=1:1:length(x)-1

jump(i)= abs(x(i)-x(i+1));

end

  

% Finding Minimum Jump

Min_Jump=Inf;

for i=1:1:length(jump)

if Min_Jump> jump(i)

Min_Jump=jump(i);

end

end

% Calculting y Matrix

s=1;

for i=1:1:length(jump)

if jump(i)==Min_Jump

y(s)=i;

s=s+1;

end

end

K=Min_Jump

y

end

Output:

>>x = [1 2 5 5 0 2 3 3];

>> FindMinJump1(x)

K =

0

y =

3 7

You are to create a matlab function that has the following form: function [K y] = FindMinJump1(x) where the lone input argument x is a vector of real numbers. M
You are to create a matlab function that has the following form: function [K y] = FindMinJump1(x) where the lone input argument x is a vector of real numbers. M

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site