How do I select the minimum value from the first column based on the corresponding value in the second column?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bhavishey Thapar
am 17 Feb. 2022
Kommentiert: Bhavishey Thapar
am 17 Feb. 2022
I have data in two columns as shown below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/897160/image.png)
I want to find the minimum value in column one but the minimum function should only consider values in the 1st column, whose corresponding value in the 2nd column is a 0.
So in the above 8 rows the minimum value would be 3 since the minimum function would only look at 3,5,7,76.
How can achieve this?
0 Kommentare
Akzeptierte Antwort
KSSV
am 17 Feb. 2022
Let A be your data.
A = [1 1; 22 1; 3 0 ; 5 0; 60 1; 76 0; 7 0; 12 0] ;
iwant = min(A(A(:,2)==0,1))
Weitere Antworten (1)
Sajid Afaque
am 17 Feb. 2022
Bearbeitet: Sajid Afaque
am 17 Feb. 2022
use the below workaround
%variable
var = [[1;22;3;5;60;76;7;12] [1;1;0;0;1;0;0;1]];
%select only the portion which has second column entries as zeroes
var1 = var(find(var(:,2) == 0),:);
%now apply the min function
min_value = min(var1(:,1));
same in one line
%
min_value = min(var(find(var(:,2) == 0),1))
Siehe auch
Kategorien
Mehr zu Large Files and Big Data 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!