How to find minimum and maximum values?

315 views (last 30 days)
Ayob on 28 Jan 2014
Edited: Stephen on 5 Sep 2018
I have to matrices A and B which both of them are p*q matrices. I want to compare each member of A and B like A(i,j) and B(i,j) and put the maximum in a matrix like C it the same position of (i,j) and the minimum in the other matrix like D in the same position of (i,j). I want to use MATLAB special features.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 28 Jan 2014
Stephen on 5 Sep 2018
@Arturo Jr Bayangks: for several matrices try this:
Clearly this would get unwieldy for lots of separate variables, which is why it is recommended to store such data in one cell array, e.g. X:
Once you notice that cat just joins all of the data into one array then you might think to skip the stage of having lots of separate arrays altogether, and simply store your data in one array to start with, e.g. Y:
Then you are on your way to writing simpler, more efficient MATLAB code.
For ND arrays with more than 2 non-scalar dimensions, increase 3 to a suitable dimension.

Sign in to comment.

More Answers (1)

Thomas on 28 Jan 2014
you can use min() & max() functions
min (matrix) %returns the minimum
max (matrix) %returns the maximum


No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!