Getting only first component from vector/matrix output
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (1)
Sean de Wolski
le 1 Avr 2011
0 votes
No. MATLAB does not support cascading indexing (except for in structures; which wouldn't be applicable here).
3 commentaires
Positronized
le 1 Avr 2011
Sean de Wolski
le 1 Avr 2011
You can use Walter's function handle, that will do it in one line. The temporary variable will still have to be created; however, in addition to the creation of the function handle and the call to it. What's so bad about having to return a temp variable?
Positronized
le 1 Avr 2011
Catégories
En savoir plus sur Delay Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!