Find equal rows between cell array and matrix into for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Riccardo Rossi
am 18 Jul. 2019
Kommentiert: Bruno Luong
am 18 Jul. 2019
Hi everybody,
i have a matrix (A) and a cell array (B) as follow:
A
-0.11 7.17 3.66
-0.09 3.45 1.55
-0.21 2.17 9.87
-0.14 4.88 6.66
B{1,1} B{1,2}
-0.09 3.45 1.55 -0.14 4.88 6.66
I need to detect the number of row of A equal to B{1,1} and B{1,2}. In this exemple i need to create a matrix or a cell array C as follow:
C
2
4
Thank you very much!
Riccardo
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 18 Jul. 2019
Bearbeitet: Bruno Luong
am 18 Jul. 2019
Try this:
A=[-0.11 7.17 3.66
-0.09 3.45 1.55
-0.21 2.17 9.87
-0.14 4.88 6.66]
B{1,1} = [-0.09 3.45 1.55]
B{1,2} = [-0.14 4.88 6.66]
C = find(ismember(A,cat(1,B{:}),'row'))
2 Kommentare
Bruno Luong
am 18 Jul. 2019
bnum = repelem((1:numel(B))',cellfun('size',B(:),1))
[tf,bloc] = ismember(A,cat(1,B{:}),'row');
C = [find(tf),bnum(bloc(tf))]
Weitere Antworten (1)
Alex Mcaulley
am 18 Jul. 2019
A = [
-0.11 7.17 3.66
-0.09 3.45 1.55
-0.21 2.17 9.87
-0.14 4.88 6.66];
B = {[-0.09 3.45 1.55],[-0.14 4.88 6.66]};
[~,C] = ismember(cell2mat(B'),A,'rows')
0 Kommentare
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!