How to find the minimum difference between the 3 elements of a vector in app designer?
3 次查看(过去 30 天)
显示 更早的评论
I need to group the elements of a matrix 3 by 3 with the minimum difference between them. I found something like that: min(min(abs(X(1)-X2))), but l have 3 values.
6 个评论
Dyuman Joshi
2023-12-11
编辑:Dyuman Joshi
2023-12-11
I am asking what logic did you follow to get that output from that particular input.
How do you define minimum difference?
采纳的回答
DGM
2023-12-12
I take this to mean the three elements of X with the smallest extreme spread. I don't see that pdist2() would work for that.
This might work, so long as the number of elements in X stays small.
X = randi([0 99],3,3)
C = nchoosek(X(:),3);
Crange = range(C,2);
row = Crange == min(Crange);
C(row,:)
From what's given, there's no reason to think that there's a unique minimum combination. The first example @Dyuman Joshi gave is a good demonstration. The example I gave will return all combinations with the same minimum spread.
7 个评论
DGM
2023-12-13
I still don't understand. How does a 3x3 array have 12 elements, and where does 4 come in?
Are you trying to find the minimal combinations left in X after removing each minimal combination?
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!