So i have a 1xn matrix x and the for loop calculates the absolute value of differences in consecutive entries of x starting with entry 3.
n=length(x);
for i=3:n
y=abs(x(i)-x(i-1));
what i need my output to be is a 2 column vector. First column displays x and second column displays zeros for the first two rows followed by the results of the for loop.
x is a loaded vector
this is my function function [ z ] = dome(x)
n=length(x);
z = zeros(n, 2);
for i=3:n;
z(3:n,2)=abs(x(i)-x(i-1));
z(:,1) = x;
end
I'm getting this as output
ans =
1.000000000000000 0 1.500000000000000 0 1.286953767623375 0.000009575517218 1.402540803539578 0.000009575517218 1.345458374023294 0.000009575517218 1.375170252816038 0.000009575517218 1.360094192761733 0.000009575517218 1.367846967592133 0.000009575517218 1.363887003884021 0.000009575517218 1.365916733390040 0.000009575517218 1.364878217193677 0.000009575517218 1.365410061169957 0.000009575517218 1.365137820669213 0.000009575517218 1.365277208524479 0.000009575517218 1.365205850297047 0.000009575517218 1.365242383718839 0.000009575517218 1.365223680225282 0.000009575517218 1.365233255742500 0.000009575517218