Mercurial > hg > octave-lojdl
changeset 14801:3c5e6971064c
fix embedding example.
examples/embedded.c: fix call to gcd in command passed to eval.
author | Carlo de Falco <cdf@users.sourceforge.net> |
---|---|
date | Sun, 24 Jun 2012 21:42:58 +0200 |
parents | a922f768ee09 |
children | d5aee269b770 0f156affb036 |
files | examples/embedded.cc |
diffstat | 1 files changed, 11 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/embedded.cc +++ b/examples/embedded.cc @@ -13,30 +13,21 @@ octave_main (2, argv.c_str_vec(), 1); octave_idx_type n = 2; - Matrix a_matrix = Matrix (1, 2); + octave_value_list in; - std::cout << "GCD of ["; - for (octave_idx_type i = 0; i < n; i++) - { - a_matrix (i) = 5 * (i + 1); - if (i != 0) - std::cout << ", " << 5 * (i + 2); - else - std::cout << 5 * (i + 2); - } - std::cout << "] is "; - - octave_value_list in = octave_value (a_matrix); + for (octave_idx_type i = 0; i < n; i++) + in(i) = octave_value (5 * (i + 1)); + octave_value_list out = feval ("gcd", in, 1); + if (!error_state && out.length () > 0) - { - a_matrix = out(0).matrix_value (); - if (a_matrix.numel () == 1) - std::cout << a_matrix(0) << "\n"; - else - std::cout << "invalid\n"; - } + std::cout << "GCD of [" + << in(0).int_value () + << ", " + << in(1).int_value () + << "] is " << out(0).int_value () + << std::endl; else std::cout << "invalid\n";