Filter löschen
Filter löschen

2D Matrix Operation

2 Ansichten (letzte 30 Tage)
Pankaja Tanjore
Pankaja Tanjore am 19 Dez. 2015
Bearbeitet: Andrei Bobrov am 20 Dez. 2015
Hello,
I have an input array
A = [ 8 4;
3 6;
2 7;
1 4;
2 3;
2 1;
3 1;
3 5;
8 6;
8 1];
I have 2 entries [8 4] and [1 4] .Now i want only [1 4] to be retained as this is minimum of two. Similarly i have three entries [2 1] [3 1] and [8 1].Out of these i want to retain only [2 1] as that is the minimum of these three eternities. Also i have two entries [3 6] and [8 6]. Out of these i want to retain only [3 6] as this is the minimum of the two entries. Final output i want is
Res=
[1 4;
2 1;
2 7;
3 5;
3 6];
Please Let me know how this is done.
Looking forward to hear from you.
Thanks
Pankaja

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 19 Dez. 2015
Bearbeitet: Andrei Bobrov am 20 Dez. 2015
t = accumarray(A(:,2),A(:,1),[],@min);
out = sortrows([t(t>0),unique(A(:,2))]);

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by