function [xn, yn, zn] = sample_x_y(x, y, z)
%function function [xn, yn, zn] = sample_x_y(x, y, z)
%This allows the user to interactively extract a subset of values of
%the vectors x and y and the matrix z.  Of course x specifies values
%along the columns of z and y specifies values along the rows.

%     Copyright J. V. Mansbridge, CSIRO, july  5 1993

k = menu('Do you want the data set to be sub-sampled?', 'yes', 'no');
if k == 1
  
  % Check that the vector lengths agree with the size of the matrix.
  
  [m, n] = size(z);
  len_y = length(y);
  len_x = length(x);
  if m ~= len_y
    str = [num2str(m) ' rows in z, but length y = ' num2str(len_y)];
    disp(str);
    stop
  end
  if n ~= len_x
    str = [num2str(n) ' columns in z, but length x = ' num2str(len_x)];
    disp(str);
    stop
  end
  
  % Get the new values of x
  
  fprintf(' x has %5.0f elements\n', len_x)
  fprintf('x = %g, %g, %g ...  %g, %g, %g', ...
      x(1), x(2), x(3), x(len_x - 2), x(len_x - 1), x(len_x))
  x1 = input('Put in the starting index  ');
  x2 = input('Put in the increment  ');
  x3 = input('Put in the finishing index  ');
  
  % Get the new values of y
  
  fprintf(' y has %5.0f elements\n', len_y)
  fprintf('y = %g, %g, %g ...  %g, %g, %g', ...
      y(1), y(2), y(3), y(len_y - 2), y(len_y - 1), y(len_y))
  y1 = input('Put in the starting index  ');
  y2 = input('Put in the increment  ');
  y3 = input('Put in the finishing index  ');
  
  % Form the subsampled vectors and matrix.
  
  str = ['xn = x(' num2str(x1) ':' num2str(x2) ':' num2str(x3) ');'];
  eval(str)
  str = ['yn = y(' num2str(y1) ':' num2str(y2) ':' num2str(y3) ');'];
  eval(str)
  str = ['zn = z(' num2str(y1) ':' num2str(y2) ':' num2str(y3) ...
      ',' num2str(x1) ':' num2str(x2) ':' num2str(x3) ');'];
  eval(str)
  
else
  xn = x;
  yn = y;
  zn = z;
end
