Asked by Tiger
on 4 May 2013

Example

A=[0 1 2 3; 4 5 6 7; 8 9 10 11]

vector=[-1,-1]

I wish I could get the answer B=[ 0 0 0 0; 1 2 3 0; 5 6 7 0]

Thank you!

*No products are associated with this question.*

Answer by the cyclist
on 4 May 2013

This is awkward, but I think it works:

% Your inputs A = [0 1 2 3; 4 5 6 7; 8 9 10 11]

vector = [-1,-1]

% The algorithm: vector(2) = -vector(2); % Because you defined the y-direction opposite to the MATLAB convention

[m,n] = size(A);

frame = zeros([m n]+abs(vector));

offset = max([0 0],-vector);

frame(offset(1)+(1:m),offset(2)+(1:n)) = A;

grab = max([0 0],vector);

B = frame(grab(1)+(1:m),grab(2)+(1:n))

Opportunities for recent engineering grads.

## 0 Comments