poster
2019-12-10, 20:48
我有一些类似的点
x=[1 1 1 2 2 4 4 5 6 ......7 8 8 9 9] 我想有一个包含3个元素的数组,该元素的最小元素数和3个元素的最大元素数(忽略相同的元素)
上面的预期结果将是
ans=[1 2 4 7 8 9]
回答:
您可以使用UNIQUE (http://www.mathworks.com/help/techdoc/ref/unique.html)函数执行此操作:
uniqueValues = unique(x); %# Get the unique values of x minmaxValues = uniqueValues([1:3 end-2:end]); %# Get the 3 smallest and largest
更多&回答... (https://stackoverflow.com/questions/4564926)
x=[1 1 1 2 2 4 4 5 6 ......7 8 8 9 9] 我想有一个包含3个元素的数组,该元素的最小元素数和3个元素的最大元素数(忽略相同的元素)
上面的预期结果将是
ans=[1 2 4 7 8 9]
回答:
您可以使用UNIQUE (http://www.mathworks.com/help/techdoc/ref/unique.html)函数执行此操作:
uniqueValues = unique(x); %# Get the unique values of x minmaxValues = uniqueValues([1:3 end-2:end]); %# Get the 3 smallest and largest
更多&回答... (https://stackoverflow.com/questions/4564926)