# about the minimum of elements of a matrix Classic List Threaded 8 messages Reply | Threaded
Open this post in threaded view
|

## about the minimum of elements of a matrix

 hello friends, is there a function that gives  a minimum a(i, j) of the elements of a matrix and the corresponding number of rows and column  (ie it returns the values of i and j). Thank you in advance. George. _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

## Re: about the minimum of elements of a matrix

 On Mon, Dec 20, 2010 at 5:02 PM, george.brida wrote: hello friends, is there a function that gives  a minimum a(i, j) of the elements of a matrix and the corresponding number of rows and column  (ie it returns the values of i and j). Thank you in advance. George. _______________________________________________ Help-octave mailing list [hidden email] https://www-old.cae.wisc.edu/mailman/listinfo/help-octave Take a look at minhelp minmm=min(min(a)))[i,ij] =find (a==mm)Doug Stewart _______________________________________________ Help-octave mailing list [hidden email] https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

## Re: about the minimum of elements of a matrix

 man, 20 12 2010 kl. 17:23 -0500, skrev Doug Stewart: > > > On Mon, Dec 20, 2010 at 5:02 PM, george.brida > <[hidden email]> wrote: >         hello friends, >         is there a function that gives  a minimum a(i, j) of the >         elements of a matrix and the corresponding number of rows and >         column  (ie it returns the values of i and j). >         Thank you in advance. >         George. >         >         >         >         >         _______________________________________________ >         Help-octave mailing list >         [hidden email] >         https://www-old.cae.wisc.edu/mailman/listinfo/help-octave>         > > Take a look at min > help min > > > mm=min(min(a))) > [i,ij] =find (a==mm) Or alternatively:         [val, idx] = min (A (:));         [i, j] = ind2sub (size (A), idx); Søren _______________________________________________ Help-octave mailing list [hidden email] https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

## Re: about the minimum of elements of a matrix

 Am Montag, 20. Dezember 2010, 23:44:58 schrieb Søren Hauberg: > man, 20 12 2010 kl. 17:23 -0500, skrev Doug Stewart: > > On Mon, Dec 20, 2010 at 5:02 PM, george.brida > > > > <[hidden email]> wrote: > >         hello friends, > >         is there a function that gives  a minimum a(i, j) of the > >         elements of a matrix and the corresponding number of rows and > >         column  (ie it returns the values of i and j). > >         Thank you in advance. > >         George. > >         > >         > >         > >         > >         _______________________________________________ > >         Help-octave mailing list > >         [hidden email] > >         https://www-old.cae.wisc.edu/mailman/listinfo/help-octave> > > > Take a look at min > > help min > > > > > > mm=min(min(a))) > > [i,ij] =find (a==mm) > > Or alternatively: > >         [val, idx] = min (A (:)); >         [i, j] = ind2sub (size (A), idx); > > Søren > This will show the first element which has the minimum value. If all index pairs are of interest where the matrix has its minimum value: val = min(A(:));  [i,j] =ind2sub(size(A),find(A==val)); _______________________________________________ Help-octave mailing list [hidden email] https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

## Re: about the minimum of elements of a matrix

 Martin Helm wrote > This will show the first element which has the minimum value. If all index pairs are of interest where the matrix has its minimum value: val = min(A(:));  [i,j] =ind2sub(size(A),find(A==val)); The problem with 'find' is that it may return a vector instead of a scalar. What about: [idxi, idxj] = min(A, [], 2); %# iterates on lines -- returns vectors [Amin, idxi] = min(idxi);    %# mimimum value and row index idxj = idxj(idxi);                %# column index
Reply | Threaded
Open this post in threaded view
|

## Re: about the minimum of elements of a matrix

 On Tue, Dec 21, 2010 at 11:00 AM, CdeMills <[hidden email]> wrote: > > > Martin Helm wrote: >> >> >>> >> This will show the first element which has the minimum value. If all index >> pairs are of interest where the matrix has its minimum value: >> >> val = min(A(:)); >>  [i,j] =ind2sub(size(A),find(A==val)); >> >> > > The problem with 'find' is that it may return a vector instead of a scalar. So what? ind2sub can perfectly handle a vector as well. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

## Re: about the minimum of elements of a matrix

 Am Montag, 27. Dezember 2010, 10:52:56 schrieb Jaroslav Hajek: > On Tue, Dec 21, 2010 at 11:00 AM, CdeMills <[hidden email]> wrote: > > Martin Helm wrote: > >> This will show the first element which has the minimum value. If all > >> index pairs are of interest where the matrix has its minimum value: > >> > >> val = min(A(:)); > >>  [i,j] =ind2sub(size(A),find(A==val)); > > > > The problem with 'find' is that it may return a vector instead of a > > scalar. > > So what? ind2sub can perfectly handle a vector as well. I also do not really understand why the vector should be a problem. Btw my ind2sub in the example is completely superflous. Doug Stewart already gave the simpler syntax which does the same, since find is clever enough to output the right result when called with two result parameters [i, j] = find(A==val) which is less noisy. I somehow did not notice that before. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

## Re: about the minimum of elements of a matrix

 On Mon, Dec 27, 2010 at 4:34 PM, Martin Helm <[hidden email]> wrote: > Am Montag, 27. Dezember 2010, 10:52:56 schrieb Jaroslav Hajek: >> On Tue, Dec 21, 2010 at 11:00 AM, CdeMills <[hidden email]> > wrote: >> > Martin Helm wrote: >> >> This will show the first element which has the minimum value. If all >> >> index pairs are of interest where the matrix has its minimum value: >> >> >> >> val = min(A(:)); >> >>  [i,j] =ind2sub(size(A),find(A==val)); >> > >> > The problem with 'find' is that it may return a vector instead of a >> > scalar. >> >> So what? ind2sub can perfectly handle a vector as well. > > I also do not really understand why the vector should be a problem. Btw my > ind2sub in the example is completely superflous. Doug Stewart already gave the > simpler syntax which does the same, since find is clever enough to output the > right result when called with two result parameters > > [i, j] = find(A==val) > > which is less noisy. I somehow did not notice that before. > The downside of it is that it doesn't generalize to >2D arrays. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave