I think you missed a line of code connecting data1 and data2 to val ?
For your other part:
combined = [data1; data2];
When you ask to plot a 2D array, plot() prefers to plot by column. Your combined would have three columns, so if you had done
you would get three lines.
I say "prefers" to plot by columns because when you pass an x, y pair,
then if x is a vector then x and y will be automatically transposed if needed so that size(x,1) = size(y,1). For example, plot(1:3, combined) would notice that x was length 3 and would automatically transpose combined to match.