MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何在MATLAB中提取N个最小点和N个最大点(忽略数组中的重复点)? (https://www.labfans.com/bbs/showthread.php?t=24280)

poster 2019-12-10 20:48

如何在MATLAB中提取N个最小点和N个最大点(忽略数组中的重复点)?
 
我有一些类似的点

x=[1 1 1 2 2 4 4 5 6 ......7 8 8 9 9] 我想有一个包含3个元素的数组,该元素的最小元素数和3个元素的最大元素数(忽略相同的元素)

上面的预期结果将是

ans=[1 2 4 7 8 9]

[B]回答:[/B]

您可以使用[URL="http://www.mathworks.com/help/techdoc/ref/unique.html"]UNIQUE[/URL]函数执行此操作:

uniqueValues = unique(x); %# Get the unique values of x minmaxValues = uniqueValues([1:3 end-2:end]); %# Get the 3 smallest and largest

[url=https://stackoverflow.com/questions/4564926]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:07

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.