Mercurial > hg > octave-lyh
comparison examples/embedded.cc @ 8097:804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
author | David Bateman <dbateman@free.fr> |
---|---|
date | Tue, 09 Sep 2008 13:43:42 -0400 |
parents | |
children | 4295d634797d |
comparison
equal
deleted
inserted
replaced
8096:01f60e8d6ae9 | 8097:804c60f92fb1 |
---|---|
1 #include <iostream> | |
2 #include <octave/oct.h> | |
3 #include <octave/octave.h> | |
4 #include <octave/parse.h> | |
5 int | |
6 main (void) | |
7 { | |
8 string_vector argv (2); | |
9 argv(0) = "embedded"; | |
10 argv(1) = "-q"; | |
11 | |
12 octave_main (2, argv.c_str_vec(), 1); | |
13 | |
14 octave_idx_type n = 2; | |
15 Matrix a_matrix = Matrix (1, 2); | |
16 | |
17 std::cout << "GCD of ["; | |
18 for (octave_idx_type i = 0; i < n; i++) | |
19 { | |
20 a_matrix (i) = 5 * (i + 1); | |
21 if (i != 0) | |
22 std::cout << ", " << 5 * (i + 2); | |
23 else | |
24 std::cout << 5 * (i + 2); | |
25 } | |
26 std::cout << "] is "; | |
27 | |
28 octave_value_list in = octave_value (a_matrix); | |
29 octave_value_list out = feval ("gcd", in, 1); | |
30 | |
31 if (!error_state && out.length () > 0) | |
32 { | |
33 a_matrix = out(0).matrix_value (); | |
34 if (a_matrix.numel () == 1) | |
35 std::cout << a_matrix(0) << "\n"; | |
36 else | |
37 std::cout << "invalid\n"; | |
38 } | |
39 else | |
40 std::cout << "invalid\n"; | |
41 | |
42 return 0; | |
43 } |