unique and min by index

3 Ansichten (letzte 30 Tage)
Tiina
Tiina am 16 Dez. 2015
Beantwortet: Walter Roberson am 16 Dez. 2015
Hi, if I have A=[1 1 1 2 2 3 3 3] as unique values and B=[ 5 6 7 4 1 2 2 3]. I want to find the min and difference as [5 5 5 1 1 2 2 2] and [0 1 2 3 0 0 0 1]. How may i do that? thanks.

Antworten (1)

Walter Roberson
Walter Roberson am 16 Dez. 2015
group_min = accumarray(A(:), B(:), [], @min);
result1 = group_min(A);
result2 = B - result1;

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by