Prev: Writting overloaded function
Next: ode45
From: Matt on 5 Aug 2010 12:23 Hello, I have a problem with finding minimums and I'm not quite sure why... Recently I have been using the code "[I,J]= find(summat == max(summat(:)))" to find my maximums in a matrix, however, now I wish to find the minimums in my matrix and when I just substitute min in for max, I get an [8million+ x 1] for I and J. I've tried several other ways, but none have yielded results for me yet. Some code along the lines ... "minnum = 1e9; for i = 1:2160; for j = 1:4320; if summat(i,j) <= minnum; minnum = summat(i,j); imin = i; jmin = j; end end end" was suggested to me, but I'm not quite sure how to make it stop and hold imin and jmin at the minimum value in summat. Any help would be great, Thanks Matt
From: Joseph on 5 Aug 2010 13:21 Matt, You may have several elements that are equal to minnum. You have to decide which one you want. Example: A = [0,1,0,0]; B = find(A == min(A(:))); disp(B) 1 3 4 "Matt " <matthew.t.sherman(a)jhuapl.org> wrote in message <i3eoh8$jgc$1(a)fred.mathworks.com>... > Hello, > > I have a problem with finding minimums and I'm not quite sure why... > Recently I have been using the code > "[I,J]= find(summat == max(summat(:)))" > > to find my maximums in a matrix, however, now I wish to find the minimums in my matrix and when I just substitute min in for max, I get an [8million+ x 1] for I and J. > > I've tried several other ways, but none have yielded results for me yet. > > Some code along the lines ... > > "minnum = 1e9; > for i = 1:2160; > for j = 1:4320; > if summat(i,j) <= minnum; > minnum = summat(i,j); > imin = i; > jmin = j; > end > end > end" > > was suggested to me, but I'm not quite sure how to make it stop and hold imin and jmin at the minimum value in summat. > > Any help would be great, > Thanks > Matt
From: Roger Stafford on 5 Aug 2010 14:06 "Matt " <matthew.t.sherman(a)jhuapl.org> wrote in message <i3eoh8$jgc$1(a)fred.mathworks.com>... > Hello, > > I have a problem with finding minimums and I'm not quite sure why... > Recently I have been using the code > "[I,J]= find(summat == max(summat(:)))" > > to find my maximums in a matrix, however, now I wish to find the minimums in my matrix and when I just substitute min in for max, I get an [8million+ x 1] for I and J. > > I've tried several other ways, but none have yielded results for me yet. > > Some code along the lines ... > > "minnum = 1e9; > for i = 1:2160; > for j = 1:4320; > if summat(i,j) <= minnum; > minnum = summat(i,j); > imin = i; > jmin = j; > end > end > end" > > was suggested to me, but I'm not quite sure how to make it stop and hold imin and jmin at the minimum value in summat. > > Any help would be great, > Thanks > Matt - - - - - - - - - - The line "[I,J]= find(summat == min(summat(:)))" ought to work. It does on my matlab version and gives all the instances where a minimum is achieved. The most likely cause of your difficulty would be that somewhere on your system you have inadvertently created a function with the name "min" and it is the one being called here instead of Mathworks' 'min'. If not that then very probably this is a real bug in your system. Did you check to see if that value you get for I and J with 'min' corresponds to the actual minimum using linear indexing on I? You can check by using 'ind2sub' on I. If it is a bug, you should report it to Mathworks' support personnel. By the way, the for-loop code you show would not be a valid replacement since it finds only one instance of a minimum. Roger Stafford
|
Pages: 1 Prev: Writting overloaded function Next: ode45 |