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

1 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2017-5-26
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:

请先登录,再进行评论。

采纳的回答

MathReallyWorks
MathReallyWorks 2017-5-26
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by