title: Changing line coordinates matlab
body: <p>I have the following code where I have two lines (L1 and L2) and I can find the point of intersection between the lines. However, L1 never changes but L2 does. This is where I am having the problem. I have a .txt file with a list of x and y coordinates. How do I alter the code such that I can swap out the figures 660 and 122.75 in L2 for the top two numbers in my list. Then save the intersection point and start again but this time replacing the two numbers with the second set of numbers in my list.</p>
  
  <p>Regards,
  Jer</p>
  
  <pre><code>    clc;
  clear;
  
  %% Load data
  
  filename = 'C:\blade1_data.txt';
  delimiter = ' ';
  formatSpec = '%f%f%[^\n\r]';
  fileID = fopen(filename,'r');
  dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true,  'ReturnOnError', false);
  fclose(fileID);
  X_coords = dataArray{:, 1};
  Y_coords = dataArray{:, 2};
  clearvars filename delimiter formatSpec fileID dataArray ans;
  
  %% Find intersection between lines
  
  L1 = [656.25 122.75;  611.625 378.875];  % Defines rotor line
  L2 = [0 122.75; 660 122.75]; % Defines coordinate where blade tip was located 
  
  
  dx = diff(L1);  %# Take the differences down each column
  dy = diff(L2);
  den = dx(1)*dy(2)-dy(1)*dx(2);  %# Precompute the denominator
  ua = (dx(2)*(L2(1)-L2(3))-dy(2)*(L1(1)-L1(3)))/den;
  ub = (dx(1)*(L2(1)-L2(3))-dy(1)*(L1(1)-L1(3)))/den;
  % Intersection point of the two lines:
  
  xi = L1(1)+ua*dx(1);
  yi = L2(1)+ua*dy(1);
  </code></pre>