%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Transform xyz data in matrix data %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [matrix_data, xgrid, ygrid] = xyz2Matrix(xyz_data)
n_points = size(xyz_data, 1);
% Count the points in the x-direction
counter_x = 1;
tmp1 = xyz_data(1, 2);
for i=2:n_points
tmp2 = xyz_data(i, 2);
if(tmp1 == tmp2)
counter_x = counter_x + 1;
end
end
% Calculate the points in the y-direction
counter_y = n_points / counter_x;
% Transform xyz data in matrix data.
xgrid = zeros(counter_y, counter_x);
ygrid = zeros(counter_y, counter_x);
matrix_data = zeros(counter_y, counter_x);
index1 = 1;
for i=1:counter_y
for j=1:counter_x
matrix_data(i, j) = xyz_data(index1, 3);
xgrid(i, j) = xyz_data(index1, 1);
ygrid(i, j) = xyz_data(index1, 2);
index1 = index1 + 1;
end
end