Finding row numbers of a matrix where certain column entries match a criterion
1 次查看(过去 30 天)
显示 更早的评论
I have a 64x3 matrix C0 as below. I would like to look at row 63=[4 4 3], and for each j=1:3, find the row numbers of C0 such that the not-j's column entries in that row equals the corresponding values in row 63. e.g. for j=1, find all rows of C0 such that the 2nd and 3rd values are [4 3]. (but would like a succinct way of writing this in a loop for all j)
Thanks for your help!
C0=[];
for R1=1:4
for R2=1:4
for R3=1:4
C0=[C0; [R1 R2 R3]];
end
end
end
0 个评论
采纳的回答
Walter Roberson
2019-4-24
find(C0(:,2) == 4 & C0(:,3) == 3)
3 个评论
Walter Roberson
2019-4-28
RowOfInterest = C0(64,:);
nc = size(C0,2);
vec = 1 : nc;
results = cell(nc,1);
mask = C0 == RowOfInterest;
for j = 1 : nc
nonj = vec; nonj(j) = [];
results{j} = find( all(mask(:,nonj), 2 ) );
end
The detection of matching rows could probably be vectorized (at the cost of temporary memory), but find() is difficult to vectorize.
更多回答(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!