Trying to extract rows of a matrix where a given column equals a range of values
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Michael Bochert
am 10 Mär. 2024
Kommentiert: Voss
am 12 Mär. 2024
Hi there, I am trying to extract rows of a matrix where the 2nd column of that matrix equals a range of values (i.e., 36-48 for example). I am then only interested in column 9 of those rows.
For example, here is some of the code I have been trying:
YFP_WithmCherry_0_plus = enlistcell_new_YFP_WithmCherry(enlistcell_new_YFP_WithmCherry(:,2)==36:48,9);
I keep getting this error: "The logical indices in position 1 contain a true value outside of the array bounds."
The following code does work, however it doesnt extract all of the rows i want:
YFP_WithmCherry_0_plus = enlistcell_new_YFP_WithmCherry(enlistcell_new_YFP_WithmCherry(:,2)==36,9);
Ive attached the data frame. Please help! Thank you.
0 Kommentare
Akzeptierte Antwort
Voss
am 10 Mär. 2024
Bearbeitet: Voss
am 10 Mär. 2024
X = load('enlistcell_new_YFP_WithmCherry.mat').enlistcell_new_YFP_WithmCherry
"2nd column ... equals a range of values (i.e., 36-48... ) ... column 9 of those rows"
One way:
idx = X(:,2) >= 36 & X(:,2) <= 48;
result = X(idx,9)
Another way, since all elements in that range in column 2 are integers:
idx = ismember(X(:,2),36:48);
result = X(idx,9)
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!