Well, Trying to do something with search engines.
I have generated a matrix (term-document) from a collection of 5 documents. The output is:
docs= (5,1) 1.0000
(1,2) 0.7071
(3,2) 0.7071
(1,3) 0.7071
(5,3) 0.7071
(3,4) 1.0000
(4,5) 1.0000
Also, I have generated a query matrix from user query.
q= (1,1) 1
(2,1) 1
I’m trying to find similarity of the document set with the user’s query applying Vector space modelling. Here goes the code:
% docs is a sprase matrix presenting a number of document.
sc=zeros(1, n); doc_inds=zeros(1, n);
% q is the user query.
sc=q'*docs;
%sort documents according to their
similarity coefficient with the query
[sc, doc_inds]=sort(sc);
sc=sc(end:-1:1);doc_inds=doc_inds(end:-1:1);
The line sc=q'*docs; always produces error saying: ??? Inner matrix dimensions must . agree.
Can anyone help me getting an idea to deal with it ? Appreciate your time.
According to the data in your example,
docsis 5×5 andqis 2×1. The matrix multiplicationq'*docsis attempting to multiply a 1×2 matrix with a 5×5 matrix. Matrix multiplication requires that the second dimension of the first matrix agrees with the first dimension of the second matrix, thus the error you are getting.Why are you defining
scat the linesc=zeros(1, n);and then overwriting it with this matrix multiplication?