[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Matrix resizing
From: |
Chengqi Zhang |
Subject: |
Re: Matrix resizing |
Date: |
Sun, 07 Mar 2010 09:21:33 +0800 |
User-agent: |
Opera Mail/10.10 (Win32) |
On Sun, 07 Mar 2010 02:03:33 +0800, Marius Roets <address@hidden>
wrote:
Is there a vectorized way to delete every other row/column in a matrix?
Similarly to duplicate every other row/column?
a=magic(7)
%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])
--
Best Regards!
---------------------------
Sincerely, Chengqi Zhang
China Center for Economic Research
Mail: address@hidden
Personal Website: http://macro2.cn
- Matrix resizing, Marius Roets, 2010/03/06
- Re: Matrix resizing,
Chengqi Zhang <=