How to concatenate two matrices in MatLab?

49 Views Asked by At

I have this small technical problem, which I search for an quick solution for. The problem is as follows. Let $$X = \begin{bmatrix} 100 &5\\ 150 &8\\ 200 &10\\ 300 & 15\end{bmatrix}$$ and $$Y = \begin{bmatrix} 50 &2\\ 100 &7\\ 200 &12\end{bmatrix}.$$ Now I wish to construct a matrix $Z$ such that $$Z = \begin{bmatrix} 50 &\mathtt{NaN} &2\\ 100 &5 &7\\ 150 &8 &\mathtt{NaN}\\ 200 &10 &12\\ 300 & 15 &\mathtt{NaN}\end{bmatrix}.$$ To put it in some context you can view the first column in $X$ and $Y$ as strike prices for an option and the second column as options prices. Is there maybe a builtin function in MatLab that can handle this? Any suggestions are welcomed. Thanks in advanced.