Prev: Infeasible start point
Next: BUFR files
From: wapo on 10 Sep 2009 10:15 Nice solution. Now lets make it a bit more difficult. What if I have the following: a=rand(3,3,10); b=eye(3); ind=[1 3 5]; for i=1:10 c(ind)=a(:,:,i).*b end So now I want the three diagonal elements in the slice to be placed in specific locations on the new matrix. This fails cause a(:,:,i).*b is 3*3 whereas logical indexing expects 3 elements. Any ideas???
From: Matt on 10 Sep 2009 11:28 wapo <apostolos1975(a)gmail.com> wrote in message <3ff7a906-f6f9-4246-8679-7467799d7f2d(a)t2g2000yqn.googlegroups.com>... > > Perhaps as follows: > > > > aa=reshape(a,9,[]); > > c=aa([1 5 9],:), > > I was hoping to avoid copying data around and read them directly from > the original matrix. There is no data copying involved here. The variable "aa" points to the exact same copy of the data as does "a".
From: Matt on 10 Sep 2009 11:32
wapo <apostolos1975(a)gmail.com> wrote in message <37bd5376-1ea6-46f3-813c-edc2419b801c(a)s39g2000yqj.googlegroups.com>... > Nice solution. Now lets make it a bit more difficult. What if I have > the following: > > a=rand(3,3,10); > b=eye(3); > ind=[1 3 5]; > for i=1:10 > c(ind)=a(:,:,i).*b > end > > So now I want the three diagonal elements in the slice to be placed in > specific locations on the new matrix. This fails cause a(:,:,i).*b is > 3*3 whereas logical indexing expects 3 elements. The following is a simple modification to what I had before, and again involves no copying of the data in "a" aa=reshape(a,9,[]); c(ind,:)=aa([1 5 9],:), |