unique and min by index

5 ビュー (過去 30 日間)
Tiina
Tiina 2015 年 12 月 16 日
回答済み: Walter Roberson 2015 年 12 月 16 日
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.

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 12 月 16 日
group_min = accumarray(A(:), B(:), [], @min);
result1 = group_min(A);
result2 = B - result1;

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by