Write a function called neighbor that takes as input a row vector called v and creates another row vector as output that contains the absolute values of the differences between neighboring elements of v. For example, if v == [1 2 4 7], then the output of the function would be [1 2 3]. Notice that the length of the output vector is one less than that of the input. Check that the input v is indeed a vector and has at least two elements and return an empty array otherwise. You are not allowed to use the diff built-‐in function.
function d = neighbor(v)for ii = 1:length(v)-1 d(ii) = abs(v(ii+1) - v(ii)); end end
Feedback: Your function performed correctly for argument(s) [1 2 3 4]
Feedback: Your function performed correctly for argument(s) [2 1] Feedback: Your function performed correctly for argument(s) [1 -2 3] Feedback: Your function performed correctly for argument(s) [5 -3 6 -7 1 4 -4 6 -5 -1] Feedback: Your function performed correctly for argument(s) [0.775665774190202 0.46043860784642 0.637754980094595 0.21592913366455 0.0321676971373623 0.777337876450925 0.979770397784413 0.221076297004035 0.063923583412422 0.129378479212439] Feedback: Your function made an error for argument(s) [1 2;3 4] Your solution is _not_ correct.
Best Answer