Find elements in vector that satisfy condition
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Danielle Sisserman
am 26 Jan. 2021
Bearbeitet: James Tursa
am 26 Jan. 2021
say that I have the following matrix X:
x1 =[1 2]
x2 = [3 2]
x3 = [3 4]
X = [x1;x2;x3]
I need to get a matrix consisting of the rows in X that that satisfy the following condition:
x(1) == 3.
So my resulting matrix will be:
S = [x2;x3] = [3 2; 3 4]
How can I do this (for any dimension index, not necessarily 1)
Thank you
0 Kommentare
Akzeptierte Antwort
James Tursa
am 26 Jan. 2021
Bearbeitet: James Tursa
am 26 Jan. 2021
X = your big matrix
k = column number you want to examine
value = some number you are looking for
idx = (X(:,k) == value); % logical indexes of the rows where the element in column k is value
S = X(idx,:); % pick off the subset of rows that have value in column k
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!