How to pick the lowest element for each row by different matrices?

1 Ansicht (letzte 30 Tage)
Hi everyone,
I have the following three matrices (5x2)
a = [41 53; 3 20; 10 40; 11 50; 55.6 111]
b = [19 27.2; 31 10; 2.1 99; 70 55; 7 23]
c = [1 34; 41 10; 11 31; 5 39; 10 22]
I'm looking for the code to create a matrix D (5x2), such that each row is picked by a, b, c with the lowest item in the first column for each row, namely I would like to obtain:
D = [1 34; 3 20; 2.1 99; 5 39; 7 23]

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 15 Mär. 2021
Bearbeitet: KALYAN ACHARJYA am 15 Mär. 2021
I'm looking for the code to create a matrix D (4x2), such that each row is picked by a, b, c with the lowest item in the first column for each row, namely I would like to obtain:
It might be 3x2 Martix in the given example?
a=
3 20
b=
2.1 99
c=
1 34
One way:
idx_a=find(a(:,1)==min(a(:,1)));
idx_b=find(b(:,1)==min(b(:,1)));
idx_c=find(c(:,1)==min(c(:,1)));
D=[a(idx_a,:);b(idx_b,:);c(idx_c,:)]
D =
3 20
2.1 99
1 34
  3 Kommentare
KALYAN ACHARJYA
KALYAN ACHARJYA am 15 Mär. 2021
data=cat(3,a,b,c);
colm1=min(data(:,1,:),[],3);
colm1 =
1
3
2.1
5
7
Get the indices of the corresponding colm1 data, extract the same from the data (column 2). Later I will try on it and provide you the complete answer.
Diego Rago
Diego Rago am 15 Mär. 2021
Thank you a lot, it works perfectly!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices 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