I have a matrix Ksets
in Matlab with size Gx(l*N)
and a matrix A
with size MxN
.
Each row of Ksets
can be decomposed into l
sub-rows with size 1xN
.
Let me explain better with an example.
clear
N=3;
l=4;
G=2;
M=5;
Ksets=[1 2 3 5 6 7 9 10 11 0 0 0;
13 14 15 1 2 3 21 22 23 1 1 1]; %Gx(l*N)
A=[1 2 3;
5 6 7;
21 22 23;
1 2 3;
0 0 0]; %MxN
In the example:
row
1
ofKsets
is composed ofl
sub-rows with size1xN
:[1 2 3]
,[5 6 7]
,[9 10 11]
,[0 0 0]
;row
2
ofKsets
is composed ofl
sub-rows with size1xN
:[13 14 15]
,[1 2 3]
,[21 22 23]
,[1 1 1]
.
I assume that each row of Ksets
does not contain equal sub-rows.
I would like your help to construct a matrix Response
with size GxM
with Response(g,m)=1
if the row A(m,:)
is equal to one of the l
sub-rows of Ksets(g,:)
and zero otherwise.
Continuing the example above
Response= [1 1 0 1 1;
1 0 1 1 0]; %GxM
This code does what I want:
Responsecorrectmy=zeros(G, M);
for x=1:G
for c=1:l
Responsecorrectmy(x,:)=Responsecorrectmy(x,:)+...
ismember(A,Ksets(x,(c-1)*N+1:c*N), 'rows').';
end
end
My code consists of 2 loops which is undesirable because in my real algorithm G,l
are big. Do you have suggestions without loops?