Background:
I have the following matrix is raw data,for example:
It can be discovered:(Also what I want to get through the program)
- The first line of a : (\left[ \begin{matrix} 1 & 2 & 3 \end{matrix} \right]) is a subset of the first (\left[ \begin{matrix} 1 & 2 & 3 &5 \end{matrix} \right]) and fourth (\left[ \begin{matrix} 2 &3 &1&6 \end{matrix} \right]) lines of b.
- The first line of b differs from the first line of a by “5”,
the fourth line of b differs from the first line of a by “6”. - According to the above ideas, the result should be like:
My code:
c = hcat(a,zeros(Int64,size(a,1),4))
for i = 1:size(a,1)
dex = Vector{Int64}()
for j = 1:size(b,1)
if a[i,:] ⊆ b[j,:]
dex = append!(dex,j)
end
end
c[i,4] = dex[1]
c[i,5] = dex[2]
end
# Determine the number of lines a belongs to b,
# here I am sure that there are only two lines in b containing a
for i = 1:size(a,1)
k1 = setdiff(b[a[i,4],:], a[i,:])
k2 = setdiff(b[a[i,5],:], a[i,:])
c[i,6] = k1[1]
c[i,7] = k2[1]
end
# Write the element different from a in b to c
Question:
When my matrix size is large, the execution efficiency of the above code is really too low.
I want to ask if you have any good suggestions or other algorithms to achieve the same purpose.(That is to get the matrix c)
If you still need other information, please let me know in the comment, I will add it in time, thank you all.