Finding row numbers of a matrix where certain column entries match a criterion
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
wy6622
am 24 Apr. 2019
Kommentiert: wy6622
am 29 Apr. 2019
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 24 Apr. 2019
find(C0(:,2) == 4 & C0(:,3) == 3)
3 Kommentare
Walter Roberson
am 28 Apr. 2019
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.
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!