MATLAB: How to create matrix X

matrix

I am trying to create a matrix X like in the attached image. I have the vectors x,y,z denoted as DE,DN,DZ respectively.

Best Answer

That is straightforward, using the (:) addressing to create column vectors regardless of their original orientation:
X = [ones(size(DE(:))) DE(:) DN(:) DZ(:)];
If you also have your ā€˜gā€™ vector (all vectors must be the same length), calculate the ā€˜aā€™ coefficients as:
a = X\g(:);
Related Question