Could anyone suggest me is there any way of choosing maximum and minimum values together

1view (last 30 days)
a = [23 42 37 18 52];
关于命令m = max(a)给出52
最小(a)给出18
有什么办法,以便我可以将52和18同时获得(最大值和最小值)
1条评论
DPB
DPB 2019年10月17日
mnmx = [min(a)max(a)];
或写自己的“句法糖”常规minmax() -
functionmnmx = minmax(x)
mnmx = [min(x(:))max(x(:))];
结尾
The latter should probably also have the ability to return the locations to mimic builtin interfaces.....and maybe treat arrays the same as them also in working on column-basis by default with the dimension as the optional argument...so many choices to make.

登录发表评论。

答案(3)


Jos (10584)
Jos (10584) 2019年10月17日
这是一个不错的技巧,也可以结合ne functions in a single call, which also can return the other outputs of these functions:
minmaxFun = @(x) cellfun(@(F) F(x), {@min, @max}) ;
[v,i] = minmaxfun([2 1 3 5 2])
%v = [1 5],i = [2 4]
You can take this a step further:
mapf = @(val,fcns)cellfun( @(f)f(val {:}),fcns);
data = randi(10, [1 10])
[minmax,minmaxidx] = mapf({data},{@min @max})
S = mapF({data}, {@mean @median @std})
您可以在洛伦(Loren)的博客上了解更多有关此的信息:

丹尼尔
丹尼尔 2019年10月17日
Edited:丹尼尔 2019年10月17日
a = [23 42 37 18 52];
minmaxvals = prctile(a,[0 100])
ans =
18 52
3条评论

登录发表评论。

标签

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!