Trying to extract rows of a matrix where a given column equals a range of values
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 10 Mar 2024
Edited: Voss
on 10 Mar 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)
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!