I really need help with this one.
I have to matrices L1
and L2
, both are (500x3)
of size.
First of all, I compute the difference of every element of each column of L1
from L2
as follows:
lib1 = bsxfun(@minus, L1(:,1)',L2(:,1));
lib1=lib1(:);
lib2 = bsxfun(@minus, L1(:,2)',L2(:,2));
lib2=lib2(:);
lib3 = bsxfun(@minus, L1(:,3)',L2(:,3));
lib3=lib3(:);
LBR = [lib1 lib2 lib3];
The result is this matrix LBR
. Then I have a min
-problem to solve:
[d,p] = min((LBR(:,1) - var1).^2 + (LBR(:,2) - var2).^2 + (LBR(:,3) - var3).^2);
Which returns the point p
where this min
-problem is fulfied. Finally I can go back to my matrices L1
and L2
to find the index-positions of the values which satisfy this min
-problem. I done this as follows:
[minindex_alongL2, minindex_alongL1] = ind2sub(size(L1),p);
This is OK. But what I need now is:
I have to multiply , take the tensor-product
, also called Kronecker product
of a vector called alpha
to LBR
, alpha
is given as follows:
alpha = 0:0.1:2;
And, this Kronecker product
I have computed as follows:
val = bsxfun(@times,LBR,permute(alpha,[3 1 2]));
LBR = reshape(permute(val,[1 3 2]),size(val,1)*size(val,3),[]);
what I need now is: I need to solve the same min
problem:
[d,p] = min((LBR(:,1) - var1).^2 + (LBR(:,2) - var2).^2 + (LBR(:,3) - var3).^2);
but, this time, in addition of finding the index-positions and values from L1
and L2
which satisfies this min
-problem, I need to find the index position of the single value from the alpha
vector which has been multiplied and which fulfills the min
-problem. I don't have idea how can I do this so any help will be very appreciated!
Thanks in advance!
Ps: I can post the L1
and L2
matrices if needed.