[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Vectorize loop.
From: |
Paul Kienzle |
Subject: |
Re: Vectorize loop. |
Date: |
Mon, 9 Oct 2006 17:35:41 -0400 |
On Oct 9, 2006, at 1:09 PM, TEJEDA HERNANDEZ, CESAR wrote:
Hello,
Does anyone know if this loop can be vectorized and how?
for k=1:rows(PDF1y)
Py1res(k,:)=PDF1y(k,aux1(k,2:22));
end
I think the following does what you want:
x=[1,2,3;1,2,3;1,2,3;1,2,3]
idx=[1,2,3;3,1,2;3,2,1]
x(sub2ind(size(x),[1:4]'*ones(1,3),idx))
ans =
1 2 3
3 1 2
3 2 1
2 3 1
- Paul