MATLAB: How to reshape 1-D to 2-D matrix with missing data

reshape

I need to reshape a 1-D array into a 2-D matrix. The difficulty is that there is random missing data so the RESHAPE function cannot be used in the typical fashion.
I have a set of 3 arrays: x-coordinates, y-coordinates, and a scalar.
For example, this is my input:
x = [ 1 1 1 1 1 2 2 3 3 3 ]
y = [ 1 2 3 4 5 1 2 1 2 5 ]
c = [ 2 1 2 1 2 1 2 1 2 1 ]
and this is my desired output:
x = [ 1 1 1 1 1 ; 2 2 2 2 2 ; 3 3 3 3 3 ]
y = [ 1 2 3 4 5 ; 1 2 3 4 5 ; 1 2 3 4 5 ]
c = [ 2 1 2 1 2 ; 1 2 NaN NaN NaN ; 1 2 NaN NaN 1 ]
Help is much appreciated.

Best Answer

I figured out the solution.
First I find the grid vectors:
xgv = sort(unique(x));
ygv = sort(unique(y));
Then I create a mesh grid:
[X,Y] = meshgrid(xgv,ygv);
Finally, I use an interpolation function, but no interpolation occurs because the points are given:
C = griddata(x,y,C,X,Y);
Thanks for your input ya'll