Prev: decompose strain tensor
Next: Plotting using loops
From: Anthony Hopf on 4 Aug 2010 22:43 Here is the issue I am having. I have an mxn matrix, that is very large. I would like to use the find command but it is pretty slow for large arrays... but I have noticed that I get a substantial improvement in speed when my mxn matrix is smaller. So now I use the find command on a much smaller subset of the initial array. I get a huge speed up in search... but how do I put those "adjusted" index values back into the original array? LargeArray = m x n; idx = find(LargeArray((m/2)-10:(m/2)+10,(n/2)-10:(n/2)+10)>0); LargeArray(idx) = 45; I get the right number of points so I assume I am finding the right values but my idx values are shifted, and I can't seem to figure out the procedure for getting them back. Thank you
From: Matt Fig on 4 Aug 2010 22:59 Do you need the find here at all? Why not just use logical indexing? A(A>0) = 45
From: TideMan on 4 Aug 2010 23:07 On Aug 5, 2:43 pm, "Anthony Hopf" <anthony.h...(a)gmail.com> wrote: > Here is the issue I am having. > > I have an mxn matrix, that is very large. I would like to use the find command but it is pretty slow for large arrays... but I have noticed that I get a substantial improvement in speed when my mxn matrix is smaller. So now I use the find command on a much smaller subset of the initial array.. I get a huge speed up in search... but how do I put those "adjusted" index values back into the original array? > > LargeArray = m x n; > idx = find(LargeArray((m/2)-10:(m/2)+10,(n/2)-10:(n/2)+10)>0); > LargeArray(idx) = 45; > > I get the right number of points so I assume I am finding the right values but my idx values are shifted, and I can't seem to figure out the procedure for getting them back. > > Thank you You could make this a lot simpler by defining a sub matrix: m1=fix(m/2)-10;m1=ceil(m/2)+10; % This allows for odd m n1=fix(n/2)-10;n2=ceil(n/2)+10; % This allows for odd n SubMx=LargeArray(m1:m2,n1:n2); idx=find(SubMx > 0); SubMx(idx)=45; LargeArray(m1:m2,n1:n2)=SubMx;
From: Anthony Hopf on 5 Aug 2010 09:00 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <i3d9dp$j6h$1(a)fred.mathworks.com>... > Do you need the find here at all? Why not just use logical indexing? > > A(A>0) = 45 Matt, this is essentially what "find" does right? the example I gave above was simplified too... I am doing a 3 dimension logical indexing... I actually have 3 arrays Rlarge, Tlarge, and Plarge. The indexes that I pull will then be used to alter the values within another array. In the end I hope to have a logical array stored in memory that I can refer back to so I don't have to do this indexing step over and over. My initial process was to use Bruno's histcn with accumarray to do the binning(extremely fast), but we are getting a little bit more specific with the emulator and need to allow for binning that doesn't necessarily have monotonically increasing binning (there may be oversampling, ect). TideMan, Thank you... this is an intuitive process that I should have seen. I just need to apply it to the 3 arrays above. Thanks again!!
From: Anthony Hopf on 5 Aug 2010 09:15
TideMan <mulgor(a)gmail.com> wrote in message <9e28098e-b1ad-475e-bb2f-159f04921953(a)i4g2000prf.googlegroups.com>... > On Aug 5, 2:43 pm, "Anthony Hopf" <anthony.h...(a)gmail.com> wrote: > > Here is the issue I am having. > > > > I have an mxn matrix, that is very large. I would like to use the find command but it is pretty slow for large arrays... but I have noticed that I get a substantial improvement in speed when my mxn matrix is smaller. So now I use the find command on a much smaller subset of the initial array. I get a huge speed up in search... but how do I put those "adjusted" index values back into the original array? > > > > LargeArray = m x n; > > idx = find(LargeArray((m/2)-10:(m/2)+10,(n/2)-10:(n/2)+10)>0); > > LargeArray(idx) = 45; > > > > I get the right number of points so I assume I am finding the right values but my idx values are shifted, and I can't seem to figure out the procedure for getting them back. > > > > Thank you > > You could make this a lot simpler by defining a sub matrix: > m1=fix(m/2)-10;m1=ceil(m/2)+10; % This allows for odd m > n1=fix(n/2)-10;n2=ceil(n/2)+10; % This allows for odd n > SubMx=LargeArray(m1:m2,n1:n2); > idx=find(SubMx > 0); > SubMx(idx)=45; > LargeArray(m1:m2,n1:n2)=SubMx; Actually, while this is a nice process, is there any way to just modify idx without having to create the SubMx? I can see how to create a logical indexing matrix... but say I want to save the index values in a cell array for use later... |