How to find the minimum difference between the 3 elements of a vector in app designer?

조회 수: 4 (최근 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
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?
piston_pim_offset
piston_pim_offset 2023년 12월 11일
It was an axample. l didn't use anything, just looked at the numbers and wrote it.

댓글을 달려면 로그인하십시오.

채택된 답변

DGM
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)
X = 3×3
65 46 98 71 61 28 91 4 26
C = nchoosek(X(:),3);
Crange = range(C,2);
row = Crange == min(Crange);
C(row,:)
ans = 1×3
65 71 61
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
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?
piston_pim_offset
piston_pim_offset 2023년 12월 13일
-Are you trying to find the minimal combinations left in X after removing each minimal combination?
+Absolutely!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 12월 11일
Try to implement pdist2()

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by