MATLAB: Getting only first component from vector/matrix output

devalfunctionvectors

I'm using ode45 to solve a second-order IVP and want to use deval to evaluate the solution.
Since the equation was second-order, the solution vector has two components. I am wondering if there's an easy way to just get only the first component without having to assign deval's output to a temporary variable first?
I would've expected syntax like (deval(sol,x))(1) to work but it doesn't.
The same question applies not just to deval, but to any function which returns a vector/matrix.

Best Answer

subsref(deval(sol,x),struct('type','()','subs',1))
If you are doing this multiple times, then just use (e.g.,)
first = @(x) x(1);
first(deval(sol,x))