How to find minimum or maximum value
Mostrar comentarios más antiguos
Hello guy's
I have three matrix's as bellow
http://www.mediafire.com/conv/d20e69eaebeea8495d0c30180c7bdf7c90204747484d04a1e20acf9790a027056g.jpg


I need your help please to get any method to find the minimum value (only one point ) with respect of all matrix's
Please Note: in these matrix's the lowest value for all matrix is x2y2.
1 comentario
Azzi Abdelmalek
el 28 de Ag. de 2012
what do you mean?
Respuestas (3)
Junaid
el 28 de Ag. de 2012
min (matrix) return the minimum. If you have more then one matrix with different dimensions then you can do it like this.
Lets assume you have three A, B, and C;
then
min([A(:); B(:); C(:)])
for example
A = magic(5);
B = magic(2);
C = magic(10);
min([A(:); B(:); C(:)])
6 comentarios
sese
el 28 de Ag. de 2012
Image Analyst
el 28 de Ag. de 2012
(:) means to just take all the elements of an n-dimensional matrix and string them all together into one long 1D vector. Then enclose three vectors in [] and that means you just concatenate all three long 1D vectors into one long vector. Then min() takes the min of that, which is the same as the min of all the elements of all the matrices. Does that explain it?
Junaid
el 28 de Ag. de 2012
Thank you for explaining. Just addition to explanation by image analyst.
Take an example.
a = [1 2 3
4 5 6
7 8 9];
then
a(:) =
1
2
3
4
5
6
7
8
9
Andrei Bobrov
el 28 de Ag. de 2012
a = [1 2 3
4 5 6
7 8 9];
a(:)
ans =
1
4
7
2
5
8
3
6
9
sese
el 28 de Ag. de 2012
Walter Roberson
el 28 de Ag. de 2012
As in min(A+B+C) ?
Image Analyst
el 28 de Ag. de 2012
You need to find the min of A, B, and C (year1, year2, and year3 matrices) separately. (Untested code)
minA = min(A(:));
minB = min(B(:));
minC = min(C(:));
Then see which is smallest.
minOverall = min([minA minB minC]);
Then find out where that value occurs in the various matrix(es):
[rowA colA] = find(A == minOverall);
[rowB colB] = find(B == minOverall);
[rowC colC] = find(C == minOverall);
The lowest overall value may occur in more than one location or matrix if you're dealing with integers.
2 comentarios
sese
el 28 de Ag. de 2012
Image Analyst
el 28 de Ag. de 2012
OK, that's fine. So you're all set.
AlgoBuilder
el 2 de Mayo de 2014
0 votos
sese,
If you have a 2D matrix of data (ex: P), you can find the min/max of the entire matrix in one line as follows: min(min(P)) max(max(P))
For a 3D matrix/image or other data, you can do the same as:
min(min(min(P))) max(max(max(P)))
Image Analyst, If you think this is in anyway not accurate or computationally expensive, please let us know.
2 comentarios
Image Analyst
el 2 de Mayo de 2014
Well sese has 3 matrices so that's why I gave the answer I did. If he/she did have a 2D matrix, then you could do
minP = min(P(:));
maxP = max(P(:));
which is more along the lines of what I did in my answer. That's what I'd do, and I think most experienced MATLAB-ers would do, since it works for any dimension array and you don't have to worry about it, like you did in your solution. Your solution will work though if you know in advance what dimensions your array is.
AlgoBuilder
el 8 de Mayo de 2014
Image Analyst, I totally agree with you.
When I code, I try to write it as possible to the explanation in my head. But there are more efficient ways of doing the same task, like you mentioned above. I need to practise more.
For the same reasons, I also have a difficult time vectorizing code.
Categorías
Más información sobre Vector and Raster Map Display en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!