Hi every one. I am going to attempt that query.. 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. I am trying that code, getting an error in for loop because its inner statement (vi+1) creating problem.To me instead of for loop while loop will be implement. But how i not know.Any correction will be highly appreciable..
function [A]=neighbor(v)if isvector(v) && length(v)>=2 % checking whether v is a vector and have two elements
for i=1:length(v) A=v(i+1)-v(i); % getting the absolute values of v(i+1)-v(i)
endelse A=[];endend
Best Answer