I have this command "min(A(:,b),[ ],2)", where A is a matrix and b is one of its columns. How does it works?

2 vues (au cours des 30 derniers jours)
Hi everyone! I have this piece in a code I am trying to understand but I don't know what does it means when "[]" and "2" are added inside the min function. Thank you for your help. :)
  1 commentaire
Stephen23
Stephen23 le 26 Mai 2017
Why not simply read the min documentation, which tells us all (including you!) how min can be used? You can easily find the min documentation using your favorite internet search engine, and it would have taken less time than joining some internet forum and waiting for some strangers to tell you how min works. (tip: those strangers know how min works because they read the documentation).
The documentation states clearly:
" M = min(A,[],dim) returns the smallest elements along dimension dim. For example, if A is a matrix, then min(A,[],2) is a column vector containing the minimum value of each row."
You might like to read this:

Connectez-vous pour commenter.

Réponse acceptée

MathReallyWorks
MathReallyWorks le 26 Mai 2017
Hello Vio,
A = [1.7 1.2 1.5; 1.3 1.6 1.99]
M = min(A,[],2) %This gives minimum along rows
and
A = [1.7 1.2 1.5; 1.3 1.6 1.99]
M = min(A,[],1) %This gives minimum along columns
If you don't use [ ] in your code, it shows a modified matrix with all the elements of A. If any value is greater than n, then it is replaced by n otherwise it is unchanged
n=6;
A = [1.7 1.2 6.5; 1.3 1.6 6.99]
M = min(A,n);
and
n=7;
A = [1.7 1.2 6.5; 1.3 1.6 6.99]
M = min(A,n);
This is something I observed while coding. Just wanted to share. I hope it will be helpful.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by