In this assignment you are to create a matlab function that
In this assignment, you are to create a matlab function that has the following form: function [K y] = FindMaxJump(x) where the lone input argument x is a vector of real numbers. The outputs describe where in vector x the maximum “jumps” occur for consecutive vector elements. That is, the output K is the size of the maximum jump and the vector y are the left-hand-side indexes where the maximum jump(s) occur. It is possible that the vector may have more than one jump at the maximum so the vector y may have more than one index value. For example, if x = [1 2 5 0 2 3]; Then the maximum “jump” occurs between the 3rd and 4th elements where the jump is -5 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. The function should output K = 5; as well as the vector y = [3]; where the 3 indicates the “left” index of where the jump occured As a second example, the input vector x = [1 3 4 2 3]; should give rise to the outputs K = 2; y = [1 3]; If the x vector is empty or has only one element, return the empty vector for both K and y. Remember that matlab requires that the function name and the file name be the same. That is, the function must be put in the file with name: FindMaxJump.m Solve the problem using the more direct approach using constructs such as for ... end, if ... else ... end, etc.
Solution
function [k, y]=findjumpmax(x)
s=length(x);
k=0;
for n=1:s-1
if abs(x(n)-x(n+1))>k
k=abs(x(n)-x(n+1));
end
end
p=0;
for z=1:s-1
if abs(x(z)-x(z+1))==k
p=p+1;
end
end
y=zeros(1,p);
n=1;
for m=1:p
q=0;
while (n<s && q==0)
if abs(x(n)-x(n+1))==k
y(m)=n;
q=1;
end
n=n+1;
end
end
>> [k,y]=findjumpmax([1 3 4 2 3])
k =
2
y =
1 3
![In this assignment, you are to create a matlab function that has the following form: function [K y] = FindMaxJump(x) where the lone input argument x is a vector In this assignment, you are to create a matlab function that has the following form: function [K y] = FindMaxJump(x) where the lone input argument x is a vector](/WebImages/1/in-this-assignment-you-are-to-create-a-matlab-function-that-969994-1761495809-0.webp)