MATLAB - minmax() function

jacksonY picture jacksonY · Apr 19, 2012 · Viewed 8.1k times · Source

I have downloaded a code which involves a minmax() function, the backbone of the code is shown below:

A = [13 5; 
    13, 13; 
    23, 26];

B = [13, 6; 
    13. 6; 
    5, 26];

C = [A;B];
Datad = minmax(C');

G = 178*Datad(1,1)/174*Datad(1,2)

and when I run the code, an error message appeared:

Undefined function or method 'minmax' for input arguments of type 'double'.

so I went onto google, and this simple code should work:

  x=1:10;
   m=minmax(x)

m =

 1    10

BUT it did not work and the same error message appeared.

Since I do not think minmax is going to work, my question here is :

Are there any other ways to replace minmax? I know there is a min and max function which could do the job. But I am not sure how would the original minmax function work for matrices, since I would need to get it right to be able to get G.

minmax function is defined as: Here

Answer

Mohsen Nosratinia picture Mohsen Nosratinia · Apr 19, 2012

Use this in your code and then you don't need a separate file.

minmax = @(x) [min(x(:)) max(x(:))];

Note that it does not support [Y,I] = minmax(X) syntax mentioned in the link you provided.