Saturday, November 5, 2011

Vectorizing: duplicating and deleting rows and columns in Octave

%1-1, To delete every other row(only the 1st, 3rd, 5th, ... left)
result=a(1:2:end,:)

%1-2, To delete every other row(only the 2nd, 4th, 6th, ... left)
result=a(2:2:end,:)


%1-3, To delete every other col(only the 1st, 3rd, 5th, ... left)
result=a(:,1:2:end)


%1-4, To delete every other row(only the 2nd, 4th, 6th, ... left)
result=a(:,2:2:end)

%2-1, To duplicate every other row(duplicate 1st, 3rd, 5th, ...)
result=kron(a(1:2:end,:),[1;1])



%2-2, To duplicate every other col(duplicate 1st, 3rd, 5th, ...)
result=kron(a(:,1:2:end),[1,1])

0 comments:

Post a Comment