开发者

MATLAB: What's [Y,I]=max(AS,[],2);?

I just started matlab and need to finish this program really fast, so I don't have time to go through all the tutorials.

can someone familiar with it please explain what the following statement is开发者_运维知识库 doing.

[Y,I]=max(AS,[],2);

The [] between AS and 2 is what's mostly confusing me. And is the max value getting assigned to both Y and I ?


According to the reference manual,

C = max(A,[],dim) returns the largest elements along the dimension of A specified by scalar dim. For example, max(A,[],1) produces the maximum values along the first dimension (the rows) of A.

[C,I] = max(...) finds the indices of the maximum values of A, and returns them in output vector I. If there are several identical maximum values, the index of the first one found is returned.

I think [] is there just to distinguish itself from max(A,B).


C = max(A,[],dim) returns the largest elements along the dimension of A specified by scalar dim. For example, max(A,[],1) produces the maximum values along the first dimension (the rows) of A.

Also, the [C, I] = max(...) form gives you the maximum values in C, and their indices (i.e. locations) in I.

Why don't you try an example, like this? Type it into MATLAB and see what you get. It should make things much easier to see.

m = [[1;6;2] [5;8;0] [9;3;5]]
max(m,[],2)


AS is matrix.
This will return the largest elements of AS in its 2nd dimension (i.e. its columns)


This function is taking AS and producing the maximum value along the second dimension of AS. It returns the max value 'Y' and the index of it 'I'.


note the apparent wrinkle in the matlab convention; there are a number of builtin functions which have signature like:

xs = sum(x,dim)

which works 'along' the dimension dim. max and min are the oddbal exceptions:

xm = max(x,dim);     %this is probably a silent semantical error!
xm = max(x,[],dim);  %this is probably what you want

I sometimes wish matlab had a binary max and a collapsing max, instead of shoving them into the same function...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜