Trying to extract rows of a matrix where a given column equals a range of values
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2024-3-10
编辑:Voss
2024-3-10
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!