The thing in the example you didn't copy is the use of line instead of plot to draw onto the second axis. plot does a lot of preparation work behind the scenes that you don't want when adding to axes such as here.
You can use plot, but to not cause the occlusion of the first axes when you draw on top of it, you need to call hold on on that axes first.
As a side note in using Matlab to its best advantage, you can remove the loop by vectorizing the expression for theta via the "dot" operators--
theta=(273.15+T).*(p0./p).^(R/Cp)-273.15;
NB: the "." (dot) in the multiply, divide and power operations to operate element-wise over the vectors as opposed to matrix operations.