# How to select matrix column from minimum row value

4 Ansichten (letzte 30 Tage)
Deon Cooper am 18 Aug. 2020
Bearbeitet: Sara Boznik am 18 Aug. 2020
I am currently doing a multi-part task, but the final step involves sorting a matrix I generated to find the lowest value in the row and selecting the whole column:
eg:
distance_to_point = [2, 3, 4, 5; 6.8, 2.9, 6.1, 6.7]
I need to pick the column that has the lowest value in the second row (the distance value), and still identify the point from which the distance is measured, so that I end up with;
new_point = [3; 2.9]
How would I do this?
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Sindar am 18 Aug. 2020
distance_to_point = [2, 3, 4, 5; 6.8, 2.9, 6.1, 6.7]
[~,idx] = min(distance_to_point(2,:));
new_point = distance_to_point(:,idx);
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Sara Boznik am 18 Aug. 2020
Bearbeitet: Sara Boznik am 18 Aug. 2020
distance_to_point = [2, 3, 4, 5; 6.8, 2.9, 6.1, 6.7]
minima=min(distance_to_point(2,:))
[m,n]=find(distance_to_point==minima)
r=distance_to_point(1,n)
new_point=[minima; r]
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

R2018b

### Community Treasure Hunt

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

Start Hunting!

Translated by