function data = reformatData(dist_cm, freq, ang, matrix)
%
% function data = reformatData(dist_cm, matrix)
% 
% This function takes an NxM matrix (MATRIX) of delta Eab (or spatial
% CIELAB delta Eab) values and a distance (DIST_CM) and converts it into a
% (N*M)x4 matrix (DATA). The frequency and orientation are contained in a
% vector (FREQ and ANG, respectively). Frequency must be a 1xN vector and
% orientation must be a 1xM vector.
%
% Each row of the output matrix is a "data point" that contains a row
% vector of 4 elements--(distance [in cm], freq [in cpd], orientation 
% [in degrees], dEab / spatial dEab value). The number of rows corresponds
% to the number of data elements in the original matrix (MATRIX).
%

[m n] = size(matrix);
if (length(freq) ~= n | length(ang) ~= m)
    error('Frequency (FREQ) or Orientation (ANG) vector is not of the right length.');
end

data = [];
for I=1:m,
    for J=1:n,
        data = [data; dist_cm freq(I) ang(J) matrix(J,I)];
    end
end
    