"aiden " <aidenjobe@gmail.com> wrote in message <i911ii$e3e$1@fred.mathworks.com>...
> Friends,
>
> I have matrix representing Line coordinates (x1 , y1 , x2 , y2) as follows:
>
> lines = [ 62 2 48 15
> 11 9 34 12
> 18 22 10 73 ]
>
> There are 4 Lines where each row is a line.
>
> So from here I'll use the notation as follows:
> P > Point on Line 1
> L > Line 2
>
> The formula I'd like to use in the computations is :
>
> (L_y1  L_y2)*P_x1 + (L_x2  L_x1)*P_y1
>
> So, for example with respect to Line 1 and Line2 (i.e. row 1 and row 2), substituting numbers into the formula would be:
>
> Point1 in Line1 in relation to Line2 = (9 12)*62 + (34  11)*2
>
> My problem is performing this equation for all Line combinations as:
>
>  Point1 in Line1 in relation to Line2 
>  Point1 in Line1 in relation to Line3 
>
>  Point1 in Line2 in relation to Line1 
>  Point1 in Line2 in relation to Line3 
>
>  Point1 in Line3 in relation to Line1 
>  Point1 in Line3 in relation to Line2 
>
> I am new to Matlab programming and would like ask for some assistance.
>
> Cheers,
> aiden
There is a code:
K = zeros(3);
for k=1:3
for j=1:3
K(k,j) = (lines(k,2)lines(k,4))*lines(j,1) + (lines(k,3)lines(k,1))*lines(j,2);
end
end
or without loops:
k = [1 1 1 2 2 2 3 3 3];
j = [1 2 3 1 2 3 1 2 3];
L = (lines(k,2)lines(k,4)).*lines(j,1) + (lines(k,3)lines(k,1)).*lines(j,2);
Grzegorz
